The Git Recovery Cheatsheet
The commands you forget when you need them most. This is the condensed version — a map from "what just happened" to "what to run." The full reference with context, edge cases, and dangerous-mode variants is in Git Unfucked.
Undoing commits
| Command | What it does |
|---|---|
| git reset HEAD~1 --soft | Undo last commit, keep changes staged |
| git reset HEAD~1 --mixed | Undo last commit, unstage changes (default) |
| git reset HEAD~1 --hard | Undo last commit, discard changes permanently |
| git commit --amend | Rewrite last commit message or add forgotten files |
| git revert <hash> | Create a new commit that undoes a specific commit (safe for shared branches) |
Rule of thumb
Use reset only on commits you have not pushed. Use revert on anything that has already left your machine.
Recovering lost work
| Command | What it does |
|---|---|
| git reflog | Show all recent HEAD positions — find commits before a hard reset |
| git checkout -b <branch> <hash> | Restore a commit from reflog onto a new branch |
| git stash list | List all stashed changesets |
| git stash pop | Apply most recent stash and remove it |
| git stash apply stash@{2} | Apply a specific stash without removing it |
Branch management
| Command | What it does |
|---|---|
| git branch -D <name> | Force-delete a branch (recoverable via reflog for ~30 days) |
| git cherry-pick <hash> | Apply a specific commit to the current branch |
| git merge --abort | Abort in-progress merge and restore pre-merge state |
| git rebase --abort | Abort in-progress rebase and restore pre-rebase state |
| git push origin <branch> --force-with-lease | Force push safely — aborts if remote has new commits |
Inspecting history
| Command | What it does |
|---|---|
| git log --oneline --graph | Compact visual branch graph |
| git diff HEAD~1 HEAD | What changed in the last commit |
| git blame <file> | Who changed which line and when |
| git show <hash> | Full diff and metadata for a specific commit |
| git bisect start | Binary search to find which commit introduced a bug |
The full version has 30+ scenarios
Dangerous rebase recovery, bisect workflows, submodule disasters, remote tracking fixes, and more — all with the context on when each approach is safe and when it will hurt you.
Get Git Unfucked →