git_revert
Revert a Git commit by creating a new commit that undoes the changes. Apply changes without committing when needed to manage repository history effectively.
Instructions
Revert a commit by creating a new commit
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| commit | Yes | Commit hash to revert | |
| cwd | No | Repository directory | |
| noCommit | No | Apply changes without committing |
Implementation Reference
- src/tools/git.ts:419-422 (handler)The git_revert tool handler function that executes the git revert command using the shared executeGitCommand helper.export async function gitRevert(args: z.infer<typeof gitRevertSchema>): Promise<ToolResponse> { const noCommitFlag = args.noCommit ? '--no-commit' : ''; return executeGitCommand(`git revert ${noCommitFlag} ${args.commit}`.trim(), args.cwd); }
- src/tools/git.ts:183-187 (schema)Zod schema used for input validation in the git_revert handler.export const gitRevertSchema = z.object({ commit: z.string().describe('Commit hash to revert'), cwd: z.string().optional().describe('Repository directory'), noCommit: z.boolean().optional().default(false).describe('Apply changes without committing') });
- src/tools/git.ts:722-734 (registration)MCP tool registration definition in the gitTools array, including name, description, and JSON input schema.{ name: 'git_revert', description: 'Revert a commit by creating a new commit', inputSchema: { type: 'object', properties: { commit: { type: 'string', description: 'Commit hash to revert' }, cwd: { type: 'string', description: 'Repository directory' }, noCommit: { type: 'boolean', default: false, description: 'Apply changes without committing' } }, required: ['commit'] } },
- src/index.ts:425-428 (registration)Dispatch handler in the main MCP server that routes git_revert calls to the handler function after validation.if (name === 'git_revert') { const validated = gitRevertSchema.parse(args); return await gitRevert(validated); }
- src/tools/git.ts:21-61 (helper)Shared helper function used by all git tools, including git_revert, to execute git commands and format responses.async function executeGitCommand(command: string, cwd?: string): Promise<ToolResponse> { try { const { stdout, stderr } = await execAsync(command, { cwd: cwd || process.cwd(), shell: '/bin/bash', maxBuffer: 10 * 1024 * 1024 // 10MB buffer }); return { content: [ { type: "text" as const, text: JSON.stringify({ success: true, command: command, stdout: stdout.trim(), stderr: stderr.trim(), cwd: cwd || process.cwd() }, null, 2) } ] }; } catch (error: any) { return { content: [ { type: "text" as const, text: JSON.stringify({ success: false, command: command, stdout: error.stdout?.trim() || '', stderr: error.stderr?.trim() || error.message, exitCode: error.code || 1, cwd: cwd || process.cwd() }, null, 2) } ], isError: true }; } }