claude-code-framework/essential/skills/emergency/git-recovery/SKILL.md
Recovers from git mistakes including undoing commits, recovering deleted files, resolving conflicts, and fixing detached HEAD. Use when user says "undo commit", "recover file", "git reset", "git mistake", "deleted by accident", "merge conflict", or mentions git errors.
npx skillsauth add tokenized2027/claude-initilization-v7 git-recoveryInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Quickly fix common git mistakes and recover lost work.
Common git mistakes:
Most common scenario: "I just committed but forgot to add a file"
# Undo commit, keep changes staged
git reset --soft HEAD~1
# Now add the forgotten file
git add forgotten-file.txt
# Commit again
git commit -m "Your message"
Keep changes unstaged:
# Undo commit, keep changes but unstaged
git reset HEAD~1
# Now you can modify files before committing again
Warning: This deletes your work. Only use if you're sure.
# Undo commit and delete all changes
git reset --hard HEAD~1
Undo last 3 commits:
git reset --hard HEAD~3
If you regret this:
# Find your commit in reflog
git reflog
# Recover it (find the commit hash from reflog)
git reset --hard [COMMIT_HASH]
File deleted but NOT committed:
# Recover one file
git checkout -- path/to/deleted-file.txt
# Or with newer git:
git restore path/to/deleted-file.txt
File deleted AND committed:
# Find when it was deleted
git log --all --full-history -- path/to/file.txt
# Restore from commit before deletion
git checkout [COMMIT_HASH]~1 -- path/to/file.txt
# Now commit the recovered file
git add path/to/file.txt
git commit -m "Recover deleted file"
Can't remember the filename:
# Search for deleted files
git log --diff-filter=D --summary | grep delete
# Or see all deleted files in last 10 commits
git log --diff-filter=D --name-only --pretty=format: HEAD~10..HEAD
Scenario: You committed to main but should have committed to feature/login
If you haven't pushed yet:
# 1. Note your commit hash
git log -1
# Copy the commit hash
# 2. Undo the commit on main (keep changes)
git reset --soft HEAD~1
# 3. Switch to correct branch (create if needed)
git checkout -b feature/login
# 4. Commit there
git commit -m "Your commit message"
# 5. Go back to main
git checkout main
If you already pushed to main:
# This is trickier - you need to revert on main
# 1. Create the feature branch from current main
git checkout -b feature/login
# 2. Go back to main
git checkout main
# 3. Revert the commit (this creates a new "undo" commit)
git revert HEAD
git push
When you see:
CONFLICT (content): Merge conflict in src/App.tsx
Automatic merge failed; fix conflicts and then commit the result.
Fix process:
# 1. See which files have conflicts
git status
# 2. Open the conflicted file
# Look for conflict markers:
# <<<<<<< HEAD
# Your changes
# =======
# Their changes
# >>>>>>> branch-name
# 3. Edit the file, choose which changes to keep
# Remove the <<<<<<< ======= >>>>>>> markers
# 4. Mark as resolved
git add path/to/resolved-file.txt
# 5. Complete the merge
git commit
Abort a merge:
# If you want to start over
git merge --abort
Accept "theirs" for all conflicts:
git checkout --theirs .
git add .
git commit
Accept "ours" for all conflicts:
git checkout --ours .
git add .
git commit
You'll see: HEAD detached at [commit]
What happened: You checked out a specific commit instead of a branch.
Fix:
# Option 1: Create a branch from here
git checkout -b new-branch-name
# Option 2: Go back to a branch
git checkout main
# If you made commits in detached HEAD:
# 1. Note the commit hash
git log -1
# 2. Go to your branch
git checkout main
# 3. Cherry-pick those commits
git cherry-pick [COMMIT_HASH]
Warning: Only do this if you're the only one using the branch.
# Undo last commit locally
git reset --hard HEAD~1
# Force push to remote
git push --force origin [BRANCH_NAME]
Safer alternative (doesn't rewrite history):
# Create a "reverse" commit
git revert HEAD
git push
Scenario: You did git reset --hard and lost work.
# 1. View reflog (shows all HEAD movements)
git reflog
# Output looks like:
# a1b2c3d HEAD@{0}: reset: moving to HEAD~1
# e4f5g6h HEAD@{1}: commit: Add feature
# i7j8k9l HEAD@{2}: commit: Fix bug
# 2. Find the commit you want to recover
# 3. Reset to that commit
git reset --hard e4f5g6h
Reflog is your time machine - it keeps commits for ~90 days.
You added files you don't want to commit:
# Unstage one file
git reset HEAD path/to/file.txt
# Unstage all files
git reset HEAD
Start over from last commit:
# Discard all uncommitted changes
git reset --hard HEAD
# Also delete untracked files
git clean -fd
User says: "I just committed to main but I should have created a feature branch"
Response:
# 1. Create the feature branch (keeps your commit)
git checkout -b feature/my-work
# 2. Go back to main
git checkout main
# 3. Reset main to before your commit
git reset --hard origin/main
# 4. Go back to your feature branch
git checkout feature/my-work
# Your commit is now on feature/my-work, main is clean
User says: "I need to undo my last commit but keep the changes"
Response:
# Undo commit, keep changes staged
git reset --soft HEAD~1
# Now modify files if needed, then commit again
git commit -m "Fixed commit message"
User says: "I deleted src/components/Header.tsx by accident and need it back"
If NOT committed:
git checkout -- src/components/Header.tsx
If already committed:
# Find the commit where you deleted it
git log --all -- src/components/Header.tsx
# Restore from one commit before deletion
git checkout [COMMIT_HASH]~1 -- src/components/Header.tsx
# Commit the recovery
git add src/components/Header.tsx
git commit -m "Recover deleted Header.tsx"
User says: "I tried to merge and got conflicts in App.tsx"
Response:
# 1. Check which files have conflicts
git status
# 2. Open App.tsx, look for these markers:
# <<<<<<< HEAD
# Your changes
# =======
# Their changes
# >>>>>>> branch-name
# 3. Edit the file: keep what you want, delete the markers
# 4. Mark as resolved
git add App.tsx
# 5. Complete the merge
git commit
# If you want to abort instead:
git merge --abort
User says: "Git says 'HEAD detached at abc123'"
Response:
# If you want to keep your changes here:
git checkout -b new-branch-name
# If you want to go back to main:
git checkout main
# Your work isn't lost - it's in reflog for 90 days
| Problem | Quick Fix |
|---------|-----------|
| Undo last commit (keep changes) | git reset --soft HEAD~1 |
| Undo last commit (discard) | git reset --hard HEAD~1 |
| Recover deleted file (uncommitted) | git checkout -- [FILE] |
| Recover deleted file (committed) | git checkout [HASH]~1 -- [FILE] |
| Committed to wrong branch | Create branch, reset original |
| Merge conflict | Edit file, remove markers, git add, git commit |
| Detached HEAD | git checkout -b new-branch or git checkout main |
| Unstage file | git reset HEAD [FILE] |
| Discard all changes | git reset --hard HEAD |
| Recover lost commits | git reflog then git reset --hard [HASH] |
Before committing:
# Always check what you're committing
git status
git diff
# Check which branch you're on
git branch
Before pushing:
# Review commits
git log --oneline -5
# Make sure you're on the right branch
git branch
Use feature branches:
# Never work directly on main
git checkout -b feature/my-work
# Do your work, commit, then merge via PR
Commit frequently:
# Small commits are easier to undo
# Instead of one big commit, do:
git add src/Header.tsx
git commit -m "Add Header component"
git add src/Footer.tsx
git commit -m "Add Footer component"
✅ Use git-recovery when:
❌ Don't use git-recovery for:
This skill fixes git mistakes. For learning git workflows, see the GIT_FOR_VIBE_CODERS guide in your framework.
development
Methodical debugging using reproducible steps, instrumentation, and root-cause analysis. Use when something is broken and you don't know why. Triggers on "bug", "broken", "not working", "error", "fails intermittently", "regression", "unexpected behavior".
development
Optimize prompts for Claude Code agents, API calls, and multi-agent orchestration. Use when writing system prompts, agent instructions, or refining LLM interactions. Triggers on "improve prompt", "write a prompt", "agent instructions", "system prompt", "prompt not working", "LLM output quality".
tools
Structured ideation and design review before any creative or constructive work. Use before building features, components, architecture, dashboards, or automation workflows. Triggers on "plan this", "design this", "brainstorm", "think through", "what should we build", "how should I approach".
testing
Generates test files for components and functions with setup, basic tests, and mocks. Use when user says "add tests", "create test", "test this component", or mentions testing.