Git Reflog
Also Known As
reflog
git recovery
lost commits
TL;DR
A log of every position HEAD has pointed to — the safety net for recovering commits after a bad reset, rebase, or accidental branch deletion.
Explanation
The reflog records every time HEAD moves: checkout, commit, reset, merge, rebase. Entries expire after 90 days by default. git reflog shows the history with hashes — you can checkout any hash to recover lost work. This is why 'I accidentally reset --hard and lost my commits' is almost always recoverable. git reflog expire and git gc prune eventually remove entries, but the 90-day default gives a generous recovery window.
Diagram
flowchart TD
ACTION[Any HEAD movement] --> REFLOG[(Reflog entries<br/>90 day retention)]
subgraph Records
COMMIT2[git commit]
CHECKOUT2[git checkout]
RESET2[git reset]
MERGE2[git merge]
REBASE2[git rebase]
end
COMMIT2 & CHECKOUT2 & RESET2 & MERGE2 & REBASE2 --> REFLOG
subgraph Recovery
VIEW[git reflog<br/>see all positions]
FIND[Find hash before mistake]
RESTORE2[git reset --hard hash<br/>or git checkout -b recovery hash]
end
REFLOG --> VIEW --> FIND --> RESTORE2
style REFLOG fill:#6e40c9,color:#fff
style RESTORE2 fill:#238636,color:#fff
style RESET2 fill:#f85149,color:#fff
Common Misconception
✗ Deleted branches permanently lose their commits — commits are only deleted by gc; reflog gives you the hash to recreate the branch any time within 90 days.
Why It Matters
The reflog is the answer to almost every 'I accidentally destroyed my work' git emergency — knowing it exists prevents panic and data loss.
Common Mistakes
- Panicking and running git commands that make things worse after an accidental reset.
- Not knowing that git reset --hard is recoverable via reflog — the commits are still there.
- Running git gc --prune=now immediately after a mistake — removes the reflog entries you need for recovery.
- Not using reflog to understand what happened before attempting recovery.
Code Examples
✗ Vulnerable
# Accidental hard reset:
git reset --hard HEAD~5 # 'I meant HEAD~1!'
# 5 commits appear lost
# Panicked response:
git gc --prune=now # DO NOT RUN — permanently deletes the commits
✓ Fixed
# Recovery via reflog:
git reflog
# Shows:
# abc1234 HEAD@{0}: reset: moving to HEAD~5 ← the mistake
# def5678 HEAD@{1}: commit: feat: add payment webhook ← lost commit
# ...
# Recover:
git reset --hard def5678 # Go back to before the mistake
# Or:
git checkout -b recovery-branch def5678 # Recover to a new branch
References
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
15 Mar 2026
Edited
22 Mar 2026
Views
25
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 1
No pings yesterday
Amazonbot 8
Perplexity 8
Ahrefs 2
SEMrush 2
Majestic 1
Google 1
Also referenced
How they use it
crawler 22
Related categories
⚡
DEV INTEL
Tools & Severity
🔵 Info
⚙ Fix effort: Low
⚡ Quick Fix
git reflog shows every HEAD movement for the last 90 days — it's your safety net for recovering from hard resets, bad rebases, and accidentally deleted branches
📦 Applies To
git
any
🔗 Prerequisites
🔍 Detection Hints
Lost commits after hard reset; accidentally deleted branch; bad rebase with no undo knowledge
Auto-detectable:
✗ No
git
⚠ Related Problems
🤖 AI Agent
Confidence: Low
False Positives: High
✗ Manual fix
Fix: Low
Context: File