BACK_TO_COURSE
The Git Rescue Kit — Undo Anything
The Reflog Is Your Time Machine
"I Think I Just Lost a Day of Work" Is Almost Never True
Git keeps a log of every place HEAD has pointed — every commit, reset, rebase, and checkout — for about 90 days by default, even commits that no longer appear on any branch. This is git reflog, and it is the single most underused safety net in git.
git reflog # every place HEAD has been, most recent first
git reset --hard HEAD@{2} # jump back to exactly where HEAD was 2 moves ago
A commit only becomes truly unrecoverable once git's garbage collector actually deletes it — which normally takes weeks, not the moment you ran a scary command.
Two More Tools for "Wait, Not Yet"
git stash # shelve uncommitted changes without committing them
git stash pop # bring them back
git commit --amend # fix the message or add a forgotten file to the LAST commit (only if unpushed)
TIP
The habit that separates "I panic-Googled how to fix git for an hour" from "I fixed it in 30 seconds": run git reflog before trying anything else. It almost always shows exactly where to jump back to.
QUIZ
Someone ran `git reset --hard` and thinks they lost three commits forever. What should they check first?
Sign in to track lesson progress and earn a certificate.SIGN IN TO SAVE PROGRESS