What is a Reflog
The reflog (reference log) is a chronological record of every change to HEAD and branch refs in your local repository. Every commit, checkout, rebase, reset, merge, and pull creates a reflog entry.
How it works
Reflog entries are stored in .git/logs/. Each entry records the old hash, new hash, who made the change, when, and what operation caused it.
git reflog
a1b2c3 HEAD@{0}: commit: Add feature
f7e9a2 HEAD@{1}: checkout: moving from main to feature
8899aa HEAD@{2}: reset: moving to HEAD~1
The HEAD@{n} syntax lets you reference any previous state. git reset --hard HEAD@{2} restores HEAD to the state two operations ago.
Reflog entries expire: 90 days for reachable commits, 30 days for unreachable commits. These are configurable via gc.reflogExpire and gc.reflogExpireUnreachable. After expiry, garbage collection may prune the referenced objects.
The reflog is local only — it is not shared via push or fetch. Each developer's reflog reflects only their own operations.
Why it matters
The reflog is Git's undo mechanism. Accidentally reset, rebased, or deleted a branch? The commits are almost certainly still in the object database, and the reflog tells you their hashes. It makes Git operations reversible for up to 90 days.
See How Git Internals Work for reflog, garbage collection, and object reachability.