
Here's a preview from my zine, How Git Works! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!

read the transcript!
a reflog is a log of commit IDs
I use the reflog to find “lost” commits: it contains every commit ID that the branch/tag/HEAD has ever pointed to.
some differences between git log main
and git reflog main
- reflog entries older than 90 days might get deleted by
git gc
- the reflog can show you where your branch was before a rebase.
git log
can’t - the reflog isn’t shared between repositories.
git log
is. - if I’m looking at the reflog, I’m having a bad day
which reflog to use?
The main two I use are:
-
git reflog
-
every single commit you’ve ever had checked out
-
has everything but very noisy
-
it’s the reflog for
HEAD
-
git reflog BRANCH
- just the history for that branch, might be less noisy
how to use the reflog
- run git reflog
- sadly stare at output until you find a log message that looks right
- look at the commit
git show $COMMIT_ID
git log $COMMIT_ID
- repeat until you find the thing
- use something like
git reset --hard $COMMIT_ID
orgit branch $NAME $COMMIT_ID
to put the commit on a branch
the reflog kind of sucks
- (sad face) if you delete a branch, git deletes its reflog
- (sad face) if you drop a stash entry, you can’t use the reflog to get it back
- (sad face) reflog entries don’t correspond exactly to git commands you ran
But it’s the best we have.
git fsck
: the last resort
If a commit isn’t in the reflog (for example if you “lost” it with git stash drop
), there’s still hope!
You can use git fsck
to list every commit ID that’s unreferenced.
I’ve never done this though: I try to avoid getting into this situation.
Saturday Morning Comics!
Want another comic like this in your email every Saturday? Sign up here!