git reflog

Inspection & Comparison

Show where HEAD and branches have been


The 'git reflog' command lists every position HEAD has had: each commit, switch, reset, merge and rebase, newest first. It is local to your repository and is the safety net for lost work — commits removed from a branch by a reset or a rebase are still listed and can be recovered with HEAD@{n}. Entries expire after 90 days by default.

Synopsis

git reflog [show] [<log-options>] [<ref>]
[ ] optional| or<arg> placeholder... repeatable--flag option

Options

Click any option to expand

Beginner (1)

Limit the list to the newest n entries (also written -<n>).

RecommendedThe newest entries are usually the ones you need

Example

git reflog -n 5

Choosing the Right Option

log vs reflog

Two histories

CommandListsShared?
git logCommits reachable from a branchYes, with the commits
git reflogEvery move of HEAD, even to commits no branch hasNo, local only

Examples

List moves of HEAD

git reflog

Newest first, with HEAD@{n} names.


Undo a reset

git reset --hard HEAD@{1}

Go back to where HEAD was one move ago.


Reflog of a branch

git reflog show main

Moves of main only.

Workflow Examples

1
git reflog

Find the entry before the reset

2
git reset --hard HEAD@{1}

Move back to it

1
git reflog

Find the last commit of that branch

2
git switch -c feature/login a1b2c3d

Recreate the branch there

Troubleshooting

The commit is not in the reflog

Cause: It was never checked out here, or the entry expired

Try git fsck --lost-found for dangling commits

HEAD@{1} points somewhere unexpected

Cause: Every switch also counts as a move

Read the reflog and pick the exact entry

Tips & Pitfalls

Best Practices

  • ✓Check git reflog before panicking about lost commits.
  • ✓Recover with a new branch first (git switch -c rescue <hash>) to inspect safely.

Common Mistakes

  • ✗Thinking a hard reset deleted commits for good — the reflog still has them.
  • ✗Waiting too long: unreachable commits disappear once reflog entries expire and git gc runs.
  • ✗Expecting the reflog on another machine — it is never pushed or cloned.

FAQ

A:

90 days for reachable entries, 30 days for unreachable ones, by default.

A:

No, it only lists. git reflog expire and delete are the ones that remove entries.