git-reset
Reset Git repository state to undo changes, move HEAD to specific commits, or restore branches using soft, mixed, or hard reset operations with safety controls for destructive actions.
Instructions
Git reset tool for repository state management. Supports soft, mixed, hard reset capabilities and reset-to-commit and reset-branch functionality. Includes safety warnings for destructive operations like hard reset.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | The reset operation to perform | |
| branch | No | Branch name (required for reset-branch operation) | |
| commit | No | Commit hash or reference (required for reset-to-commit, optional for others) | |
| confirmDestructive | No | Explicit confirmation for destructive operations (required for hard reset) | |
| files | No | Specific files to reset (for mixed/soft resets) | |
| force | No | Force reset - required for hard reset operations | |
| projectPath | Yes | Absolute path to the project directory | |
| quiet | No | Suppress output during reset operation | |
| skipWarning | No | Skip safety warnings (use with extreme caution - not recommended) |
Implementation Reference
- src/tools/git-reset.ts:46-126 (handler)Main handler implementation: GitResetTool.execute() method that orchestrates parameter validation, safety warnings, repository checks, and dispatches to specific reset operations (soft, mixed, hard, reset-to-commit, reset-branch).async execute(params: GitResetParams): Promise<ToolResult> { const startTime = Date.now(); try { // Validate basic parameters const validation = ParameterValidator.validateToolParams('git-reset', params); if (!validation.isValid) { return OperationErrorHandler.createToolError( 'VALIDATION_ERROR', `Parameter validation failed: ${validation.errors.join(', ')}`, params.action, { validationErrors: validation.errors }, validation.suggestions ); } // Validate operation-specific parameters const operationValidation = this.validateOperationParams(params); if (!operationValidation.isValid) { return OperationErrorHandler.createToolError( 'VALIDATION_ERROR', `Operation validation failed: ${operationValidation.errors.join(', ')}`, params.action, { validationErrors: operationValidation.errors }, operationValidation.suggestions ); } // Check for destructive operations and show safety warnings if (!params.skipWarning) { const warningResult = this.checkSafetyWarnings(params); if (warningResult) { return warningResult; } } // Check if it's a Git repository const isRepo = await this.gitExecutor.isGitRepository(params.projectPath); if (!isRepo) { return OperationErrorHandler.createToolError( 'NOT_A_GIT_REPOSITORY', 'The specified path is not a Git repository', params.action, { projectPath: params.projectPath }, ['Initialize a Git repository first with: git init'] ); } // Route to appropriate handler switch (params.action) { case 'soft': return await this.handleSoftReset(params, startTime); case 'mixed': return await this.handleMixedReset(params, startTime); case 'hard': return await this.handleHardReset(params, startTime); case 'reset-to-commit': return await this.handleResetToCommit(params, startTime); case 'reset-branch': return await this.handleResetBranch(params, startTime); default: return OperationErrorHandler.createToolError( 'UNSUPPORTED_OPERATION', `Operation '${params.action}' is not supported`, params.action, {}, ['Use one of: soft, mixed, hard, reset-to-commit, reset-branch'] ); } } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error'; return OperationErrorHandler.createToolError( 'EXECUTION_ERROR', `Failed to execute ${params.action}: ${errorMessage}`, params.action, { error: errorMessage }, ['Check the error details and try again'] ); } }
- src/tools/git-reset.ts:575-624 (schema)Tool schema definition including name, description, and detailed inputSchema with all parameters (action enum, projectPath required, optional commit/branch/files/force/quiet/skipWarning/confirmDestructive).static getToolSchema() { return { name: 'git-reset', description: 'Git reset tool for repository state management. Supports soft, mixed, hard reset capabilities and reset-to-commit and reset-branch functionality. Includes safety warnings for destructive operations like hard reset.', inputSchema: { type: 'object', properties: { action: { type: 'string', enum: ['soft', 'mixed', 'hard', 'reset-to-commit', 'reset-branch'], description: 'The reset operation to perform' }, projectPath: { type: 'string', description: 'Absolute path to the project directory' }, commit: { type: 'string', description: 'Commit hash or reference (required for reset-to-commit, optional for others)' }, branch: { type: 'string', description: 'Branch name (required for reset-branch operation)' }, files: { type: 'array', items: { type: 'string' }, description: 'Specific files to reset (for mixed/soft resets)' }, force: { type: 'boolean', description: 'Force reset - required for hard reset operations' }, quiet: { type: 'boolean', description: 'Suppress output during reset operation' }, skipWarning: { type: 'boolean', description: 'Skip safety warnings (use with extreme caution - not recommended)' }, confirmDestructive: { type: 'boolean', description: 'Explicit confirmation for destructive operations (required for hard reset)' } }, required: ['action', 'projectPath'] } }; }
- src/server.ts:133-133 (registration)Tool schema registration in ListToolsRequestSchema handler: GitResetTool.getToolSchema() included in the returned tools array.GitResetTool.getToolSchema(),
- src/server.ts:486-487 (registration)Tool dispatch registration in CallToolRequestSchema's executeTool switch: maps 'git-reset' name to this.gitResetTool.execute(args).case 'git-reset': return await this.gitResetTool.execute(args);
- src/server.ts:97-97 (registration)Instantiation of GitResetTool instance during server initialization with provider configuration.this.gitResetTool = new GitResetTool(providerConfig);