recovery

git reflog

Shows the log of updates to branch tips and HEAD stored locally, even after commits are dropped from history. The rescue rope for recovering 'lost' commits.

git reflog [<subcommand>] [<options>] [<ref>]

Common flags

Flag Purpose
show <ref> Display reflog entries for a specific ref
expire Prune old reflog entries
delete <entry> Remove specific reflog entries
--date=iso Show timestamps in ISO format
--all Show reflogs for every ref

Examples

git reflog

See recent HEAD movements — great after a bad reset

git reset --hard HEAD@{2}

Jump HEAD back to state 2 moves ago

git reflog show main

History of updates to the main branch tip

Gotcha

Reflog is local-only and expires after 90 days by default; recover lost commits promptly before garbage collection removes them.

Related commands

← All Git commands · Git cheat sheet · Git rebase vs merge