git_revert
Revert a Git branch to a specific commit or state in your local repository. Optionally stage changes without committing. Simplify branch rollback with this tool.
Instructions
Revert the current branch to a commit or state.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| commit | No | Commit hash or reference to revert | |
| no_commit | No | Whether to stage changes without committing | |
| repo_path | Yes | The path to the local Git repository |
Implementation Reference
- src/handlers/other-operations.js:214-282 (handler)The core handler function that executes the git revert operation. It uses simpleGit to run 'git revert' with optional --no-commit flag, handles errors like conflicts, and returns structured JSON responses.export async function handleGitRevert({ repo_path, commit, no_commit = false, }) { try { const git = simpleGit(repo_path); if (!commit) { return { content: [ { type: "text", text: JSON.stringify( { error: "Commit reference is required" }, null, 2 ), }, ], isError: true, }; } // Build the revert command const revertOptions = []; if (no_commit) { revertOptions.push("--no-commit"); } // Perform the revert const result = await git.raw(["revert", ...revertOptions, commit]); return { content: [ { type: "text", text: JSON.stringify( { success: true, message: `Reverted commit ${commit}`, commit: commit, result: result, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify( { error: `Failed to revert commit: ${error.message}`, conflicts: error.git ? error.git.conflicts : null, }, null, 2 ), }, ], isError: true, }; } }
- src/server.js:827-848 (schema)Input schema definition for the git_revert tool, specifying parameters repo_path (required), commit, and no_commit with descriptions.name: "git_revert", description: "Revert the current branch to a commit or state.", inputSchema: { type: "object", properties: { repo_path: { type: "string", description: "The path to the local Git repository", }, commit: { type: "string", description: "Commit hash or reference to revert", }, no_commit: { type: "boolean", description: "Whether to stage changes without committing", default: false, }, }, required: ["repo_path"], }, },
- src/server.js:926-926 (registration)Registers the 'git_revert' tool name to the handleGitRevert function in the central handlersMap used by the MCP server.git_revert: handleGitRevert,
- src/handlers/index.js:86-86 (registration)Re-exports handleGitRevert from other-operations.js for centralized handler imports.handleGitRevert,
- src/handlers/index.js:37-37 (registration)Imports handleGitRevert from './other-operations.js' into the index module.handleGitRevert,