Skip to Content
Navigation:

A stick figure smiling

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!

Image of a comic. To read the full HTML alt text, click "read the transcript". get the zine!
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

  1. run git reflog
  2. sadly stare at output until you find a log message that looks right
  3. look at the commit
    git show $COMMIT_ID
    git log $COMMIT_ID
  1. repeat until you find the thing
  2. use something like git reset --hard $COMMIT_ID or git 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!

I'll send you one of my favourite comics from my archives every Saturday.
© Julia Evans 2025 | All rights reserved (see the FAQ for notes about licensing)