Git Reflog
The reflog is Git's private log of every place HEAD has pointed on your machine, and it's the single best tool for recovering commits that seem to have vanished.
What the reflog records
Every time HEAD moves — a commit, a checkout, a rebase, a reset, a merge, even an amend — Git appends an entry to the reflog. This is a purely local, per-repository record; it isn't pushed to remotes and isn't shared with collaborators. It exists specifically as a safety net for you, tracking where your own HEAD has been over roughly the last 90 days by default.
Viewing recent HEAD movements
$ git reflog
4d5e6f7 (HEAD -> main) HEAD@{0}: commit: fix null pointer in refund calc
8g9h0i1 HEAD@{1}: rebase (finish): returning to refs/heads/feature/nav
8g9h0i1 HEAD@{2}: rebase (pick): add validation for refund amount
a1b2c3d HEAD@{3}: checkout: moving from main to feature/nav
9f8e7d6 HEAD@{4}: commit: add refund UIRecovering a commit lost to a hard reset
The most common panic moment reflog solves: you ran git reset --hard one commit too far, or reset to entirely the wrong commit, and now git log shows your work is gone. It isn't actually gone — the commit object still exists in Git's database until garbage collection eventually cleans it up, and the reflog still knows its hash.
Recovering from an over-aggressive reset
$ git reset --hard HEAD~3
HEAD is now at 9f8e7d6 add refund UI
$ git reflog
9f8e7d6 HEAD@{0}: reset: moving to HEAD~3
4d5e6f7 HEAD@{1}: commit: fix null pointer in refund calc
$ git reset --hard HEAD@{1}
HEAD is now at 4d5e6f7 fix null pointer in refund calcRecovering a deleted branch
Deleting a branch with git branch -D doesn't delete its commits either — it only removes the pointer. As long as you know (or can find) the last commit hash the branch pointed to, you can recreate the branch from that hash using the reflog.
Restoring an accidentally deleted branch
$ git branch -D feature/nav-redesign
Deleted branch feature/nav-redesign (was 8g9h0i1).
$ git reflog | grep nav-redesign
8g9h0i1 HEAD@{2}: checkout: moving from main to feature/nav-redesign
$ git branch feature/nav-redesign 8g9h0i1
$ git checkout feature/nav-redesignReflog entries vs. regular commit history
Reflog is local-only — a limitation worth knowing
Because the reflog lives only in your local .git directory, it cannot help a teammate recover a commit that only ever existed on their machine, and it can't be inspected on the remote server. If a commit was pushed at any point, though, the remote's own reflog or the reflog on anyone else who fetched it may still have a copy — which is one more reason to push work-in-progress branches regularly rather than keeping days of history only on your laptop.
Exercise: Git Reflog
What does `git reflog` primarily track?