Privacy Policy
© 2026 linux101.dev

Git: Reflog

Use git reflog to inspect the local history of updates to references such as HEAD and branch tips. It can help you find commits after a reset, rebase, amended commit, or accidental branch deletion. Unlike git log, reflog records reference movements, not just the commit ancestry.

CommandDescription
git reflogShow the reflog for HEAD, including commits, resets, rebases, and branch switches.
git reflog -n 10Show only the ten most recent entries.
git reflog show masterShow updates to the local master branch. Replace it with your branch name.
git reflog show --allShow entries from all available reflogs in this repository.
git reflog --date=isoShow timestamps instead of numbered selectors to help locate an earlier state.
git show 'HEAD@{1}'Inspect the commit from the previous recorded position of HEAD.

Read Reflog Entries

a1b2c3d HEAD@{0}: reset: moving to HEAD~1
b2c3d4e HEAD@{1}: commit: Add feature tests
a1b2c3d HEAD@{2}: commit: Add feature

Entries are listed newest first. Each line contains a commit hash, a reflog selector, and the action that moved the reference to that commit. In this example, HEAD@{0} is the latest recorded position, while HEAD@{1} points to the commit before the reset. Reflog numbers count reference updates, not parent commits: HEAD@{1} is not necessarily the same as HEAD~1.

Recover a Commit After a Reset, Rebase, or Amend

Find the desired commit in the reflog, inspect it, and create a branch to keep it reachable. For the reset example above:

git reflog
git show 'HEAD@{1}'
git branch recovered-work 'HEAD@{1}'

Creating the branch does not change your current branch, staged changes, or working files. Commit or stash any uncommitted changes before switching to it:

git switch recovered-work

For your own recovery, replace 'HEAD@{1}' with the selector or commit hash you verified. Selectors can change as new actions add reflog entries, so use the recorded commit hash if you perform other operations before creating the recovery branch.

Recover a Deleted Branch

Deleting a branch also deletes its branch reflog, but its tip may still appear in the HEAD reflog if you previously checked it out, or in another surviving reflog. Search the available entries and inspect a candidate commit:

git reflog show --all
git show <commit-hash>
git branch restored-feature <commit-hash>

Replace <commit-hash> with the actual hash of the old branch tip. The new branch preserves that commit and its ancestors without resetting your current branch.

⚠️ Recovery Limits:
Reflogs are local to a repository; they are not transferred by pushing or cloning.

Entries expire: by default, expiration thresholds are 90 days for ordinary entries and 30 days for entries unreachable from the current tip, though configuration can change these values. Once entries expire, unreachable commits may eventually be pruned by garbage collection. Create a recovery branch promptly.

Reflog is not a backup of uncommitted files and cannot reliably recover discarded working-tree changes. Avoid git reset --hard during recovery: it can discard uncommitted work. Creating a branch at a verified commit is the safer starting point.

Desktop Ad Placeholder