Skip to main content
Glama

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
NameRequiredDescriptionDefault
commitNoCommit hash or reference to revert
no_commitNoWhether to stage changes without committing
repo_pathYesThe path to the local Git repository

Implementation Reference

  • 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, }; } }
  • 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,
  • Re-exports handleGitRevert from other-operations.js for centralized handler imports.
    handleGitRevert,
  • Imports handleGitRevert from './other-operations.js' into the index module.
    handleGitRevert,

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bsreeram08/git-commands-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server