Skip to main content
Glama
bsreeram08

Git Repo Browser MCP

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

Implementation Reference

  • 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,
        };
      }
    }
  • 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,
  • Re-export of handleGitRevert from other-operations.js for centralized handler imports.
    handleGitRevert,
  • Import of handleGitRevert from other-operations.js.
    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