THE GITHTML FIELD GUIDE

Find a lost Git commit with the local reflog

Git reflog records local reference movements such as commits, resets, and checkouts. Use it to locate a previous tip, verify the candidate commit with read-only inspection, and create a recovery branch. Reflog is local and retention-limited; it does not automatically recover another clone’s activity or content Git never recorded.

Distinguish history from reference movement

Git log follows commit ancestry from selected references. Reflog answers where a local reference pointed over time. After a reset or rebase, a commit may disappear from the current branch’s ordinary log while still appearing in reflog evidence. That difference makes reflog useful for locating a prior state without immediately changing the current one.

Entries describe operations, not a curated list of valuable checkpoints. A reset entry can point to the state after the reset, while the previous entry may contain the old tip. Read timestamps, messages, and adjacent entries together. Avoid copying a familiar HEAD@{1} expression from a tutorial because additional operations can change what that position means.

Inspect candidates and preserve the right one

Use timestamps to narrow the search, then inspect the candidate’s message, patch, and ancestry. The example’s COMMIT placeholder is an explicit verified identifier. Creating a new branch protects that committed history without moving your current branch or replacing working files. Choose an unused recovery name.

  1. Check the content that mattered to the lost task, not only the commit subject. Similar messages can identify different attempts or replayed commits.
  2. Preserve the discovered commit before experimenting with reset, rebase, cleanup, or other commands that make the evidence harder to follow.
shell
git reflog --date=iso
git show --no-patch --format=fuller COMMIT
git show --stat COMMIT
git log --oneline -5 COMMIT
git branch recovery/located-commit COMMIT

Understand what recovery cannot establish

Reflog entries are not shared through normal clone or push operations, and they expire according to configuration and maintenance. If an operation happened in another clone, inspect that clone or an authorized remote rather than expecting your current reflog to contain it. Unsaved editor content and never-recorded untracked files are outside this mechanism.

Once a recovery branch exists, decide how to use it: compare against the current state, cherry-pick a focused fix, or retain it for investigation. Do not overwrite the current branch solely because the candidate looks familiar. Keep a short note of the original event, recovered identifier, and verification performed so the recovery remains understandable after the local reflog changes.

  1. When several reflog entries share a commit message after a rebase, inspect the candidate’s parent and actual patch. The pre-rebase and replayed commits can have different bases despite similar subjects. Recover the one matching the desired state rather than selecting whichever matching message appears first.
  2. Copy the verified full commit identifier into your recovery note before running more commands that move HEAD. Relative reflog positions such as HEAD@{1} describe a changing local sequence. An explicit identifier keeps the candidate unambiguous while you compare it with the current branch.

Sources and further reading

AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.

All fixing git problems guides →

Read as MarkdownAll guides

Find a lost Git commit with the local reflog · gitHtml