← All writing
Craft · · 2 min

git reflog

Git Small Print

I ran git reset --hard on the wrong branch once and spent a genuinely unpleasant ten minutes before somebody told me about this.

terminal
git reflog
Text

It prints every position HEAD has held in this repository, most recent first, with the command that moved it. Resets, checkouts, merges, rebases, commits, all of it.

terminal
a1b2c3d HEAD@{0}: reset: moving to HEAD~3
9f8e7d6 HEAD@{1}: commit: Add the delivery cutoff check
Text

The commit I thought I had destroyed is 9f8e7d6, sitting right there. git checkout -b recover 9f8e7d6 and it is back.

Two things worth knowing about it. It is local and personal, so it is not in the clone your coworker has and it does not survive a fresh clone of your own. And entries expire, ninety days by default for reachable commits and thirty for unreachable ones. So this is a safety net for last week rather than for last year.

The mental model that stuck for me: committing in git is close to permanent, and nearly every command that looks destructive is only moving a pointer. The commit is still on disk with nothing pointing at it. reflog is the list of things that used to point at it.

Which is also, from the other direction, exactly why a password committed once is a problem forever.

Read similar posts
2 min

git bisect

Halving a commit log is a mechanical process that finds a regression while you make coffee, and the only genuinely hard part is writing down what you are looking for before you start.

2 min

light-dark()

Two color values in one declaration, picked by the color scheme, which removes most of the reason a theme needed a second block of custom properties at all.