Skip to main content
Glama

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
NameRequiredDescriptionDefault
actionYesThe reset operation to perform
branchNoBranch name (required for reset-branch operation)
commitNoCommit hash or reference (required for reset-to-commit, optional for others)
confirmDestructiveNoExplicit confirmation for destructive operations (required for hard reset)
filesNoSpecific files to reset (for mixed/soft resets)
forceNoForce reset - required for hard reset operations
projectPathYesAbsolute path to the project directory
quietNoSuppress output during reset operation
skipWarningNoSkip safety warnings (use with extreme caution - not recommended)

Implementation Reference

  • 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'] ); } }
  • 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);

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/Andre-Buzeli/git-mcp'

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