git_reset
Reset Git repository HEAD to a specified commit using soft, mixed, or hard modes to undo changes and restore previous states in development workflows.
Instructions
Reset current HEAD to specified state
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | No | Repository directory | |
| mode | No | Reset mode | mixed |
| commit | No | Commit to reset to | HEAD |
| files | No | Specific file(s) to reset |
Implementation Reference
- src/tools/git.ts:411-417 (handler)The main handler function gitReset that executes the git reset command. It handles both file-specific resets and full resets with soft/mixed/hard modes using the shared executeGitCommand helper.export async function gitReset(args: z.infer<typeof gitResetSchema>): Promise<ToolResponse> { if (args.files) { return executeGitCommand(`git reset ${args.commit} -- ${args.files}`, args.cwd); } const modeFlag = `--${args.mode}`; return executeGitCommand(`git reset ${modeFlag} ${args.commit}`, args.cwd); }
- src/tools/git.ts:176-181 (schema)Zod schema defining the input parameters for the git_reset tool, including cwd, mode, commit, and optional files.export const gitResetSchema = z.object({ cwd: z.string().optional().describe('Repository directory'), mode: z.enum(['soft', 'mixed', 'hard']).optional().default('mixed').describe('Reset mode'), commit: z.string().optional().default('HEAD').describe('Commit to reset to'), files: z.string().optional().describe('Specific file(s) to reset') });
- src/tools/git.ts:709-721 (registration)The tool registration object within the gitTools array that defines the git_reset tool for the MCP listTools endpoint.{ name: 'git_reset', description: 'Reset current HEAD to specified state', inputSchema: { type: 'object', properties: { cwd: { type: 'string', description: 'Repository directory' }, mode: { type: 'string', enum: ['soft', 'mixed', 'hard'], default: 'mixed', description: 'Reset mode' }, commit: { type: 'string', default: 'HEAD', description: 'Commit to reset to' }, files: { type: 'string', description: 'Specific file(s) to reset' } } } },
- src/index.ts:421-424 (registration)Dispatch/registration logic in the main MCP server handler that routes 'git_reset' calls to the gitReset function after schema validation.if (name === 'git_reset') { const validated = gitResetSchema.parse(args); return await gitReset(validated); }
- src/tools/git.ts:21-61 (helper)Shared helper function executeGitCommand used by gitReset (and all git tools) to run git commands and format responses.async function executeGitCommand(command: string, cwd?: string): Promise<ToolResponse> { try { const { stdout, stderr } = await execAsync(command, { cwd: cwd || process.cwd(), shell: '/bin/bash', maxBuffer: 10 * 1024 * 1024 // 10MB buffer }); return { content: [ { type: "text" as const, text: JSON.stringify({ success: true, command: command, stdout: stdout.trim(), stderr: stderr.trim(), cwd: cwd || process.cwd() }, null, 2) } ] }; } catch (error: any) { return { content: [ { type: "text" as const, text: JSON.stringify({ success: false, command: command, stdout: error.stdout?.trim() || '', stderr: error.stderr?.trim() || error.message, exitCode: error.code || 1, cwd: cwd || process.cwd() }, null, 2) } ], isError: true }; } }