Reflog: Git's Black Box Recorder

A commit was discarded. A branch was force-pushed over. git remembers both.

git reflog is a real, complete, purely local log of every single place HEAD has pointed to — every commit, every checkout, every reset, every rebase, every amend. It is not part of the real commit graph and is never pushed or shared; it is the honest, private diary of everything that has genuinely happened in this one real repository.\n\nTwo real, ordinary mistakes already happened in this ~/team-recipes clone: a commit was made and then discarded with a real reset --hard, and a branch was amended and genuinely force-pushed over. Neither commit is reachable from any current real branch — but reflog remembers exactly where each one is.

Every Real Place HEAD Has Been

git reflog

Every real checkout, commit, reset, rebase, and amend — newest first, each with its own real resulting commit hash.

A Commit That "Vanished"

git reflog | grep "draft notes"
git show $(git reflog | grep "draft notes" | head -1 | cut -d' ' -f1)

A commit made and then discarded with reset --hard is genuinely gone from any current branch — but reflog still names its real hash, and the commit object itself is still on disk until real garbage collection eventually runs.

A Branch, Rewritten

git reflog feature/recipe-search

Every real branch has its own reflog, not just HEAD's. An amend followed by a force-push shows up here as two real, distinct entries — the new commit, and (one step further back) the exact original it replaced.

git reflog

A real, complete, local-only log of everywhere HEAD (or a specific branch) has pointed to. Confirmed directly in this lab: a commit invisible to git log on any current branch was still fully readable via git show once found through reflog.

Reflog expiry

Reflog entries are not kept forever — git's real defaults expire reachable entries after 90 days and unreachable ones after 30, then real garbage collection can remove the underlying objects entirely. Reflog is a safety net for recent real mistakes, not permanent archival.

📼 Read the Real Black Box

See every real place HEAD has genuinely been, most recent first.

cd ~/team-recipes && git reflog | head -10

student@lab:~$ cd ~/team-recipes && git reflog | head -10 289f47e HEAD@{0}: checkout: moving from feature/recipe-search to master 2d1cf1a HEAD@{1}: commit (amend): Add recipe search feature (reworded for clarity) 8e0429e HEAD@{2}: checkout: moving from master to feature/recipe-search 289f47e HEAD@{3}: reset: moving to HEAD~1 9c3c191 HEAD@{4}: commit: Add draft notes (oops, not ready) 289f47e HEAD@{5}: checkout: moving from master to master 289f47e HEAD@{6}: commit: Include the filename in check-times.sh's failure message 9bddb49 HEAD@{7}: commit: Add saffron rice recipe 6257452 HEAD@{8}: commit: Rename roast-chicken.md to oven-roast-chicken.md for clarity 52b09a8 HEAD@{9}: checkout: moving from master to master

🔎 Find the Commit That Vanished

A real commit was made, then discarded with reset --hard. It is still findable.

cd ~/team-recipes && git reflog | grep "draft notes"
cd ~/team-recipes && git show $(git reflog | grep "draft notes" | head -1 | cut -d' ' -f1)

student@lab:~$ cd ~/team-recipes && git reflog | grep "draft notes" 9c3c191 HEAD@{4}: commit: Add draft notes (oops, not ready) student@lab:~$ cd ~/team-recipes && git show $(git reflog | grep "draft notes" | head -1 | cut -d' ' -f1) commit 9c3c19160fa8de51c4262cf6aca85b12aaa72e41 Author: Ada Lovelace <ada@example.com> Date: Fri Jan 2 20:50:00 2026 +0000 Add draft notes (oops, not ready) diff --git a/draft-notes.md b/draft-notes.md new file mode 100644 index 0000000..d58cd4f --- /dev/null +++ b/draft-notes.md @@ -0,0 +1 @@ +Draft Notes

🔄 Find the Branch That Got Rewritten

A real amend, then a real force-push. The branch's own reflog remembers both.

cd ~/team-recipes && git reflog feature/recipe-search

student@lab:~$ cd ~/team-recipes && git reflog feature/recipe-search 2d1cf1a (origin/feature/recipe-search, feature/recipe-search) feature/recipe-search@{0}: commit (amend): Add recipe search feature (reworded for clarity) 8e0429e feature/recipe-search@{1}: rebase (finish): refs/heads/feature/recipe-search onto 5b3d7b365bafff600cca08eafda025dea9311154 40046fe feature/recipe-search@{2}: commit: fix typo in search description c504d86 feature/recipe-search@{3}: rebase (finish): refs/heads/feature/recipe-search onto 5b3d7b365bafff600cca08eafda025dea9311154 477b64c feature/recipe-search@{4}: commit: WIP e0cbd6b feature/recipe-search@{5}: commit: WIP a6c2dfd feature/recipe-search@{6}: commit: WIP 737c641 feature/recipe-search@{7}: commit: WIP 5b3d7b3 feature/recipe-search@{8}: branch: Created from HEAD

Lab 3.4.1 complete. Two real, ordinary mistakes, both still fully findable:\n\n\n Discarded commit : ✅ found via git reflog | grep\n Force-pushed branch: ✅ found via git reflog <branch>\n

Enable JavaScript to run the live terminal and track your progress.