09/30/2026

Git Recovery in Six Slides: Undo, Recover, Unbreak

The commands you need twice a year

Nobody memorizes the git commands for the bad day. This deck keeps them in one place: six slides, each with the exact commands and what they do to your files. Use the arrow keys or the Next button. With scripts off, the slides read in order below.

Run the check on the first slide before you try anything else. Most recoveries start with what it shows.

Git recovery, slide by slide

  1. Git recovery: run git status, git stash list and git reflog first; a dropped commit stays recoverable for at least 30 days
    Look firstgit status && git stash list && git reflog -20 answers three questions: what is uncommitted, what is set aside, and where HEAD has been.
  2. git reset HEAD~1 in three flavors: --soft keeps changes staged, --mixed keeps them unstaged, --hard discards them and overwrites files
    Three kinds of resetOnly --hard touches your files. --soft and --mixed move the branch pointer and leave the working tree as it is.
  3. Reset moves the branch pointer back and drops a commit; revert adds a new commit that undoes it and keeps history
    Reset or revertOn anything you have pushed and others have pulled, use revert: it adds a commit instead of rewriting history.
  4. Recover lost work: run git reflog, create a branch at the lost sha, then switch to it
    Reflog rescueMake the branch first, then look. A named branch keeps the commit from being cleaned up.
  5. Committed to the wrong branch: create a branch at this commit, reset main to origin/main, then switch to the new branch
    Wrong branchThe order matters: create the branch before you reset main, and commit or stash anything uncommitted first, because --hard discards it.
  6. Stuck in a rebase or merge: git rebase --abort and git merge --abort return you to where you started
    Escape a rebase or mergegit status says which one you are in. Abort puts you back where you started. If you cannot abort, fix the files, git add them and continue.

Where the rest is

Stash, clean and the other ways to lose work quietly are on the Git recovery cheat sheet.