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
| Item | What it does |
|---|---|
| show <ref> | Show the reflog for a specific ref |
| HEAD@{n} | The state of HEAD n moves ago |
| expire | Prune old reflog entries |
| --date=iso | Show 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
git reset: Usage, Options & Common CI Errorsgit reset moves HEAD and optionally the index and working tree. Reference for --soft, --mixed, --hard, and ho…
git rebase: Usage, Options & Common CI Errorsgit rebase replays commits onto a new base to keep history linear. Reference for -i, --onto, --continue, --ab…
git fsck: Usage, Options & Common CI Errorsgit fsck verifies object-database integrity and finds dangling or corrupt objects. Reference for --full, --lo…
git gc: Usage, Options & Common CI Errorsgit gc compresses and prunes the object database to keep the repo fast and small. Reference for --aggressive,…