GIT / A CONCEPT NOTE
The Reflog
git's undo button
Overview · mechanism
pitfall · examples
01 / THE SHORT VERSION
The idea in a few sentences.
Git maintains a local log (reflog) recording every time branch pointers move (checkouts, commits, rebases, resets). It allows you to recover deleted branches or lost commits.
02 / FOLLOW THE MECHANISM
How the reflog recovers commits
Mistake
developer runs git reset --hard HEAD~1, deleting their work commit.
Query
runs git reflog, listing previous pointer locations.
Identify SHA
locates commit hash before reset: HEAD@{1} was 'feat: new app'.
Recovery
runs git checkout or git reset to recover commit files instantly.
04 / COMMAND NOTES
Read the command, then the result.
Inspect the flags and arguments before trying an example. Snippets can need local setup, replacement values, or resources in your own environment.
show history of local branch pointer updates
git reflogrevert repo pointer back to a reflog state
git reset --hard HEAD@{1}05 / CHECK YOURSELF
Could you explain The Reflog to a teammate?
Try it out loud in two sentences: what it is, and the one detail that changes the picture. If you stall, the gap is the part to reread.