Git Reference / Reflog: the safety net
11Reflog: the safety net
Git records every move of HEAD for ~90 days. If you committed it, you can almost always get it back — even after a bad reset --hard or a deleted branch.
Find where you were
Every checkout, commit, reset, rebase.
git reflog git reflog show feature git log -g --oneline
Recover
Point a branch back at the lost commit.
git reset --hard HEAD@{2} # go back 2 moves
git branch recovered a1b2c3d # resurrect a branch
git switch main@{yesterday} --detachUndo a bad rebase
ORIG_HEAD remembers where you started.
git reset --hard ORIG_HEAD
Find dangling objects
Last resort for things never on a branch.
git fsck --lost-found git fsck --unreachable | grep commit