git reflog
Show the reference log — your safety net for lost commits
Practical example
git reflog
# abc1234 HEAD@{0}: commit: Fix login bug
# def5678 HEAD@{1}: reset: moving to HEAD~1
# Recover: git branch recovered-branch abc1234Command overview & how it works
Records every movement of HEAD — every checkout, commit, reset, rebase, and merge. When you accidentally lose commits (from a hard reset, rebase gone wrong, or deleted branch), the reflog is your recovery tool. Each entry shows the operation, the previous position, and how HEAD moved. Use git reflog to find the commit hash of a lost state, then git checkout <hash> or git branch <name> <hash> to recover it. The reflog is local — it is not shared with remotes and is not backed up. Entries expire after 90 days (for reachable commits) or 30 days (for unreachable). Use git reflog show <branch-name> to see the reflog for a specific branch. The reflog is why Git is hard to permanently lose data from.
Disaster-proof your Git workflow with the Field Guide
Learn how to rescue deleted branches, revive detached HEADs, and undo bad rebases without panic. 97-page PDF + ePub — ₹499.
Practical tips
- Check git reflog first whenever a reset or rebase 'loses' work — your commits are usually still recoverable.
- The reflog is local to your machine and not shared with remotes, so push important branches early.
- Recreate a deleted branch with git branch <name> <hash> using the hash you find in the reflog.
Deep-dive guides & tutorials
In-depth walkthroughs and practical scenarios related to git reflog
- Tutorial
How to Undo Almost Anything in Git
From amending commits to recovering deleted branches — a practical guide to Git's safety net commands.
7 min readRead guide - Tutorial
Git Reflog: Recover Lost Commits and Branches
Deleted a branch? Lost commits after a reset? Git reflog tracks every movement of HEAD and can recover what seems lost forever.
5 min readRead guide - Tutorial
Git Stash: Save and Restore Work in Progress
Stop committing half-finished work. Learn how git stash temporarily shelves changes so you can switch contexts cleanly.
5 min readRead guide
Related commands
More from Inspecting History