Quick recovery from common git mistakes including undo commits, recover branches, and reflog operations
Recovers from common git mistakes including undoing commits, restoring branches, and using reflog.
/plugin marketplace add yonatangross/skillforge-claude-plugin/plugin install skillforge-complete@skillforgeThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Interactive recovery from common git mistakes. Safe operations with verification steps.
/git-recovery
When invoked, present these options to the user:
Scenario: You committed but want to modify the changes before recommitting.
# Check current state first
git log --oneline -3
git status
# Undo commit, keep changes staged
git reset --soft HEAD~1
# Verify
git status # Changes should be staged
git log --oneline -1 # Previous commit is now HEAD
Safety: Non-destructive. All changes remain staged.
Scenario: You committed something completely wrong and want to throw it away.
WARNING: DESTRUCTIVE - Changes will be lost!
# CRITICAL: First, save a backup reference
BACKUP_REF=$(git rev-parse HEAD)
echo "Backup ref: $BACKUP_REF (save this to recover if needed)"
# Show what will be lost
git show HEAD --stat
# Confirm with user before proceeding
# Then execute:
git reset --hard HEAD~1
# Verify
git log --oneline -3
git status # Should be clean
Recovery: If you made a mistake, run git reset --hard $BACKUP_REF
Scenario: You deleted a branch and need it back.
# Find the branch's last commit in reflog
git reflog | grep -i "branch-name"
# Or search all recent activity:
git reflog --all | head -30
# Once you find the commit hash (e.g., abc1234):
git checkout -b recovered-branch abc1234
# Verify
git log --oneline -5
git branch -v | grep recovered
Note: Reflog keeps entries for ~90 days by default.
Scenario: You modified a file and want to discard local changes.
WARNING: DESTRUCTIVE - Uncommitted changes to file will be lost!
# Show current changes to file
git diff path/to/file
# Confirm with user before proceeding
# Then restore:
git checkout HEAD -- path/to/file
# Or using newer git restore (Git 2.23+):
git restore path/to/file
# Verify
git status path/to/file # Should show no changes
git diff path/to/file # Should be empty
Scenario: A rebase went wrong and you want to return to pre-rebase state.
# Find the pre-rebase state
git reflog | head -20
# Look for entry like: "rebase (start): checkout main"
# The entry BEFORE that is your pre-rebase state
# Alternative: ORIG_HEAD is set automatically before rebase
git log --oneline ORIG_HEAD -3
# Reset to pre-rebase state
git reset --hard ORIG_HEAD
# Verify
git log --oneline -5
git status
Safety: ORIG_HEAD is overwritten by other operations, use reflog if ORIG_HEAD is stale.
Scenario: You merged a branch and want to undo it.
# If merge commit exists and NOT pushed:
git log --oneline -5 # Find the merge commit
# Reset to before merge
git reset --hard HEAD~1
# If you need to specify which parent:
git reset --hard ORIG_HEAD
# Verify
git log --oneline -5
git branch -v
WARNING: If already pushed, use git revert -m 1 <merge-commit> instead to create a new commit that undoes the merge.
Scenario: You lost commits and need to find them.
# View full reflog with dates
git reflog --date=relative
# Search for specific text in commit messages
git reflog | xargs -I {} git log -1 --format="%h %s" {} 2>/dev/null | grep "search-term"
# Show reflog for specific branch
git reflog show branch-name
# Once found (e.g., abc1234), examine it:
git show abc1234
# Recover by creating a branch or cherry-picking:
git branch recovered-work abc1234
# Or:
git cherry-pick abc1234
Scenario: You staged files you didn't mean to stage.
# Unstage specific file
git reset HEAD path/to/file
# Or using newer git restore (Git 2.23+):
git restore --staged path/to/file
# Unstage all files
git reset HEAD
# Verify
git status # Files should be unstaged but modified
Safety: Non-destructive. Changes remain in working directory.
When /git-recovery is invoked:
Show current git state:
git status
git log --oneline -5
Present recovery options:
Git Recovery Options:
1. Undo last commit (keep changes staged)
2. Undo last commit (discard changes) [DESTRUCTIVE]
3. Recover deleted branch
4. Reset file to last commit [DESTRUCTIVE]
5. Undo a rebase
6. Undo a merge
7. Find lost commits (reflog search)
8. Unstage files
Which scenario? (1-8):
For destructive operations:
After recovery:
--force on shared branches without explicit user confirmation| Problem | Wrong Approach | Right Approach |
|---|---|---|
| Undo pushed commit | git reset --hard | git revert <commit> |
| Recover deleted branch | Panic | git reflog + checkout |
| Undo rebase on shared branch | git reset | git revert each commit |
| Lost commits after reset | Assume lost | git reflog saves the day |
Activates when the user asks about AI prompts, needs prompt templates, wants to search for prompts, or mentions prompts.chat. Use for discovering, retrieving, and improving prompts.
Activates when the user asks about Agent Skills, wants to find reusable AI capabilities, needs to install skills, or mentions skills for Claude. Use for discovering, retrieving, and installing skills.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.