git_revert
Undo changes by reverting a Git branch to a specific commit or state, allowing you to stage changes without committing if needed.
Instructions
Revert the current branch to a commit or state.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_path | Yes | The path to the local Git repository | |
| commit | No | Commit hash or reference to revert | |
| no_commit | No | Whether to stage changes without committing |
Implementation Reference
- src/handlers/other-operations.js:214-282 (handler)Main handler function that performs Git revert operation using simpleGit, handling options like no-commit and error cases including conflicts.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:826-848 (schema)Tool schema definition for git_revert including input parameters validation: repo_path (required), commit, no_commit (default false).{ 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)Registration of the git_revert tool name to its handler function handleGitRevert in the handlersMap.git_revert: handleGitRevert,
- src/handlers/index.js:86-86 (registration)Re-export of handleGitRevert from other-operations.js for centralized handler imports.handleGitRevert,
- src/handlers/index.js:37-37 (registration)Import of handleGitRevert from other-operations.js.handleGitRevert,