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
| Name | Required | Description | Default |
|---|---|---|---|
| mode | No | Reset mode: soft (keep changes staged), mixed (unstage changes), hard (discard changes) | mixed |
| pathspec | No | Limit reset to specific paths | |
| repoPath | Yes | Absolute path to the git repository | |
| target | No | Target 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'), };
- packages/mcp-git/src/tools/reset.ts:40-42 (registration)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); }
- packages/mcp-git/src/index.ts:26-26 (registration)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'; }