git_reset
Unstage all staged changes in a Git repository. Use this tool to revert files in the staging area to their previous state, ensuring clarity in your next commit. Requires specifying the repository path for operation.
Instructions
Unstages all staged changes
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_path | Yes |
Implementation Reference
- Core handler function implementing git reset with support for soft, mixed, hard modes, optional target (commit/branch), and specific files. Includes validation, status reporting, and error handling.def git_reset( repo: Repo, mode: str | None = None, target: str | None = None, files: list[str] | None = None, ) -> str: """Reset repository with advanced options (--soft, --mixed, --hard)""" try: # Validate reset mode valid_modes = ["soft", "mixed", "hard"] if mode and mode not in valid_modes: return ( f"❌ Invalid reset mode '{mode}'. Valid modes: {', '.join(valid_modes)}" ) # Build git reset command reset_args = [] # Add mode flag if specified if mode: reset_args.append(f"--{mode}") # Add target if specified if target: # Validate target exists try: repo.git.rev_parse(target) except GitCommandError: return f"❌ Target '{target}' does not exist" reset_args.append(target) # Add files if specified if files: # Validate files exist for file in files: if not os.path.exists(os.path.join(repo.working_dir, file)): return f"❌ File '{file}' does not exist" reset_args.extend(files) # Special handling for file-specific reset if files and not mode and not target: # Default to mixed reset for files reset_args.insert(0, "HEAD") # Get status before reset for informative message status_before = "" if mode in ["mixed", "hard"] or not mode: try: staged_files = [ item.a_path for item in repo.index.diff("HEAD") if item.a_path ] if staged_files: status_before = f"staged files: {', '.join(staged_files[:5])}" if len(staged_files) > 5: status_before += f" (and {len(staged_files) - 5} more)" except Exception: pass if mode == "hard": try: modified_files = [ item.a_path for item in repo.index.diff(None) if item.a_path ] if modified_files: mod_status = f"modified files: {', '.join(modified_files[:5])}" if len(modified_files) > 5: mod_status += f" (and {len(modified_files) - 5} more)" status_before = ( f"{status_before}, {mod_status}" if status_before else mod_status ) except Exception: pass # Execute reset if reset_args: repo.git.reset(*reset_args) else: repo.git.reset() # Build success message if files: return f"✅ Reset {len(files)} file(s): {', '.join(files)}" elif mode == "soft": return f"✅ Soft reset to {target if target else 'HEAD'} - keeping changes in index" elif mode == "mixed" or not mode: target_msg = f" to {target}" if target else "" return f"✅ Mixed reset{target_msg} - {status_before if status_before else 'no staged changes'}" elif mode == "hard": target_msg = f" to {target}" if target else "" return f"✅ Hard reset{target_msg} - {status_before if status_before else 'no changes'} discarded" else: # Fallback return (should not reach here) return "✅ Reset completed" except GitCommandError as e: return f"❌ Reset failed: {str(e)}" except Exception as e: return f"❌ Reset error: {str(e)}"
- Pydantic input schema/model for the git_reset tool defining parameters: repo_path, mode (soft/mixed/hard), target, files.class GitReset(BaseModel): repo_path: str mode: str | None = None # --soft, --mixed, --hard target: str | None = None # commit hash, branch, tag files: list[str] | None = None # specific files to reset
- src/mcp_server_git/core/handlers.py:89-90 (registration)Registration of the git_reset tool handler using _create_git_handler wrapper with repo requirement.), "git_reset": self._create_git_handler(git_reset, requires_repo=True),
- src/mcp_server_git/core/tools.py:222-229 (registration)Tool definition and registration in the ToolRegistry for 'git_reset' (RESET enum) with schema GitReset and Git category.ToolDefinition( name=GitTools.RESET, category=ToolCategory.GIT, description="Unstage all staged changes", schema=GitReset, handler=placeholder_handler, requires_repo=True, ),
- Protected wrapper for git_reset that adds repository binding validation and remote integrity checks before calling the core git_reset function.async def protected_git_reset( self, repo_path: str, mode: str = "mixed", target: str | None = None ) -> str: """Git reset with repository binding protection.""" validated_path = await self._validate_and_prepare_operation(repo_path) repo = Repo(validated_path) return git_reset(repo, mode, target)