Skip to main content
Glama

reset

Reset a Git repository to a specified commit, branch, or tag using soft, mixed, or hard modes. Manage repository state by keeping changes staged, unstaging changes, or discarding changes entirely.

Instructions

Reset repository state (soft, mixed, hard).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modeNoReset mode: soft (keep changes staged), mixed (unstage changes), hard (discard changes)mixed
pathspecNoLimit reset to specific paths
repoPathYesAbsolute path to the git repository
targetNoTarget commit, branch, or tag to reset to (defaults to HEAD)HEAD

Implementation Reference

  • The #handle method executes the git reset command using simple-git, validates the repo, constructs arguments based on input (target, mode, pathspec), runs sg.reset(), and returns formatted results or error.
    readonly #handle: ToolCallback<typeof GIT_RESET_INPUT_SCHEMA> = async (input) => { const sg = simpleGit(input.repoPath); const isRepo = await sg.checkIsRepo(); if (!isRepo) { return { isError: true, content: [ { type: 'text', text: 'Not a git repository', }, ], }; } const target = input.target ?? 'HEAD'; const args = [`--${input.mode}`, target]; if (input.pathspec && input.pathspec.length > 0) { args.push('--', ...input.pathspec); } const result = await sg.reset(args); return { content: [ { type: 'text', text: `Reset ${input.mode} to ${target}${input.pathspec ? ` (paths: ${input.pathspec.join(', ')})` : ''}`, }, { type: 'text', text: JSON.stringify(result), }, ], }; };
  • Zod input schema for the reset tool defining parameters: repoPath (required string), target (optional string default HEAD), mode (enum soft/mixed/hard default mixed), pathspec (optional array of strings).
    export const GIT_RESET_INPUT_SCHEMA = { repoPath: z.string().describe('Absolute path to the git repository'), target: z .string() .optional() .describe('Target commit, branch, or tag to reset to (defaults to HEAD)') .default('HEAD'), mode: z .enum(['soft', 'mixed', 'hard']) .optional() .default('mixed') .describe('Reset mode: soft (keep changes staged), mixed (unstage changes), hard (discard changes)'), pathspec: z.array(z.string()).optional().describe('Limit reset to specific paths'), };
  • The register method of GitResetTool class which calls srv.registerTool with the tool's name ('reset'), config (including schema), and handler.
    register(srv: McpServer) { srv.registerTool(this.name, this.config, this.#handle); }
  • Instantiation and registration of GitResetTool on the MCP server in the main index file.
    new GitResetTool().register(server);
  • Getter that returns the tool name 'reset' used during registration.
    get name() { return 'reset'; }

Other Tools

Related Tools

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/ver0-project/mcps'

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