Skip to content
Latchkey

git reflog: Usage, Options & Common CI Errors

git reflog is your safety net: a local log of every move HEAD has made.

When a reset or rebase loses commits, reflog still knows the old SHAs so you can get them back.

What it does

git reflog shows the history of where HEAD (and other refs) have pointed, including states no longer reachable from any branch. It is local-only and not pushed.

Common usage

Terminal
git reflog
git reflog show main
# recover a lost commit:
git reset --hard HEAD@{2}
git checkout -b rescue <sha-from-reflog>

Options

ItemWhat it does
show <ref>Show the reflog for a specific ref
HEAD@{n}The state of HEAD n moves ago
expirePrune old reflog entries
--date=isoShow absolute timestamps

Common errors in CI

CI checkouts are usually fresh clones with little or no reflog, so reflog-based recovery is a local-developer tool, not a CI one. Note that git gc and reflog expiry (default 90 days) eventually drop unreachable entries.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →