Guide
Undoing and recovering in Git: the commands for common situations
Git rarely loses work, but it is easy to get into a state where you do not know how to get out: a commit on the wrong branch, a reset that went too far, a branch deleted a moment too soon. The right command usually exists and is short, but finding it under pressure is hard. This finder lists 33 recipes for common situations, searchable in plain English, with the risky ones clearly marked.
How the finder is organised
Recipes are grouped by the job: undoing changes, recovering lost work, managing branches, rewriting history, putting work aside, dealing with files, inspecting history, tagging releases and basic setup. Type what you want in your own words, such as “undo commit” or “deleted branch”; every word must appear in the task, the command, the note or the group, so adding words narrows the list. Each recipe shows the commands, a copy button and a note on what to watch for.
Rewrite or add a commit
Most undo recipes come in two flavours. Commands such as git reset and git commit --amend rewrite history: they are perfect for commits that only exist on your machine. Commands such as git revert add a new commit that reverses an old one and are the safe choice once a commit has been pushed, because other people’s clones still contain the original. When you do rewrite a pushed branch, the recipes use git push --force-with-lease, which refuses to overwrite commits someone else pushed in the meantime.
The reflog is the safety net
Every time HEAD moves, through commits, resets, rebases, checkouts or merges, Git records the previous position in the reflog. git reflog lists those positions with short descriptions, and git reset --hard HEAD@{2} or git branch rescue <sha> brings any of them back. The Recover group is built around it, along with git fsck for dropped stashes.
Branches, stashes and worktrees
The Branches group covers creating, renaming and deleting branches locally and on the remote, pruning references to deleted remote branches and moving commits made on the wrong branch. Work in progress covers git stash push -u with a message and git worktree add, which checks out a second branch in another folder so you can fix something urgent without stashing.
A worked example
Searching “deleted branch” shows “Restore a deleted branch” with two commands: git reflog, then git branch feature <sha>. Find the last commit of the deleted branch in the reflog, usually the entry just before you switched away from it, and create a new branch pointing at that commit; the work comes back exactly as it was. With the search box empty, all 33 recipes are listed.
Destructive commands
Recipes that throw away uncommitted work, such as discarding all local changes with git reset --hard and git clean -fd, or rewriting all history to remove a secret, carry a red “Destroys work” badge and a note. Before running one, create a safety branch with git branch backup-now; it costs nothing and makes the operation reversible for committed work. Changes that were never committed or stashed cannot be recovered afterwards.
Habits that make mistakes cheap
Commit early on a branch, even with rough messages you will squash later; committed work is recoverable. Fetch before rebasing, read git status before destructive commands, and prefer git switch and git restore, which separate switching branches from discarding file changes, over the older all-purpose git checkout.
Related tools
- Conventional Commit Builder writes clear commit messages.
- .gitignore Generator keeps unwanted files out of commits.
- Diff Checker compares two versions of a file side by side.
- SSH Config Generator sets up keys for Git hosting.
Checked against the current version of the Git Command Finder on .

