Git Reflog Command Examples

git reflog records every movement of HEAD in your local repository — commits, resets, checkouts, rebases, and merges. This makes it the ultimate safety net for recovering from "I just destroyed my work" situations. Deleted branches, lost commits, and bad resets can almost always be recovered with reflog.

GitReflogRecoveryCLI
Viewing Reflog
View the full reflog
git reflog
Shows the complete history of HEAD movements in reverse chronological order. Each entry shows the short SHA, the reflog index (HEAD@{N}), the action (commit, checkout, reset, etc.), and the commit message. This is where you look when something goes wrong.
View reflog with timestamps
git reflog --date=iso
Adds ISO timestamps to each reflog entry. Useful for finding the state of your repository at a specific point in time — for example, to recover work that was lost before a specific hour of the day.
View reflog for a specific branch
git reflog show feature-branch
Shows the reflog for a specific branch reference instead of HEAD. Useful for seeing all the commits a branch pointed to, even after force-pushes or rebases changed its history.
Recovery Operations
Undo a git reset --hard
# Find the commit before the bad reset
git reflog
# Reset back to it
git reset --hard HEAD@{3}
Even after git reset --hard, reflog records the previous state. Find the entry just before the reset in the reflog output, then reset back to it. This is the most common recovery use case and saves developers daily.
Recover a deleted branch
# Find the last commit of the deleted branch
git reflog
# Recreate the branch pointing to that commit
git branch recovered-branch HEAD@{5}
When you delete a branch, the commits still exist in the object store temporarily. Use reflog to find the commit SHA from the deleted branch, then create a new branch pointing to it to recover all the work.
Checkout a past state from reflog
git checkout HEAD@{10}
Checks out the state of the repository as it was at reflog entry 10. This puts you in "detached HEAD" state, letting you inspect or copy files from that point. Create a branch from here to preserve the state permanently.
Cherry-pick a lost commit from reflog
git cherry-pick HEAD@{7}
Instead of resetting to a past state, cherry-pick applies only the changes from a specific reflog entry to your current branch. Useful when you want to recover one specific commit without discarding more recent work.
Stash Reflog
View stash reflog
git reflog show stash
Shows the reflog for the stash reference. Even stashes that were dropped with git stash drop or git stash clear may still be visible here. You can recover dropped stashes by cherry-picking their SHA from this list.
Recover a dropped stash
# Find the SHA of the dropped stash
git reflog show stash
# Apply it directly
git stash apply SHA
If you accidentally dropped a stash, find its SHA in the stash reflog and apply it. This works as long as Git hasn't garbage collected the object yet (typically safe for up to 90 days by default).

How to Use

  1. Run git reflog immediately after an accidental reset or deletion.
  2. Find the HEAD@{N} entry that represents the state you want to recover.
  3. Use git reset --hard HEAD@{N} to restore to that exact state.
  4. Or use git branch new-branch HEAD@{N} to create a branch without losing current work.

Frequently Asked Questions

How long does reflog keep entries?

By default, reflog entries expire after 90 days (unreachable objects after 30 days). You can change this with git config gc.reflogExpire. Once an entry expires and Git garbage collects it, the data is permanently gone — so act quickly when recovering lost work.

Is reflog available on remote repositories?

No — reflog is strictly local. Remote repositories (like GitHub) do not keep reflog entries for your pushes. However, as long as you haven't run git gc locally and the expiry hasn't passed, your local reflog has everything you need to recover.

What is the difference between git log and git reflog?

git log shows the commit history of a branch — only commits reachable from the current HEAD. git reflog shows every movement of HEAD including checkouts, resets, and rebases. Reflog can find commits that are no longer in any branch's history.

Related Tools