What is git reflog, and how does it save you?
Quick Answer
git reflog records every time HEAD moved — every commit, checkout, reset, rebase and merge — locally, for ~90 days. So a “lost” commit after reset --hard, a botched rebase, or a deleted branch is almost always recoverable: find its SHA in the reflog and git checkout / git branch / git reset back to it.
The reflog is Git's local record of everywhere HEAD has been — every commit, checkout, reset, rebase. So when someone panics because they ran git reset --hard and their commits are gone, they're not actually gone: git reflog shows the SHA the branch was at before, and you just git branch or git reset back to it. Same for a bad rebase or a deleted local branch. The caveats are that it's only on that one machine and unreferenced commits do get cleaned up eventually, so you fix it soon.
git reflog→ lines likeabc123 HEAD@{2}: reset: moving to HEAD~3.- Recover:
git branch recovered abc123orgit reset --hard HEAD@{2}. - It's per-repository and per-clone — not pushed. It only helps on the machine where the operation happened.
- Unreferenced commits are only garbage-collected after the reflog expiry, so act within days.