🔀 The Safety Net That Was Already Gone When You Reached for It
The reflog is what makes commands like git reset –hard or an amended commit recoverable – it keeps a local history of every position a branch tip has pointed to, even after a rewrite that makes a commit unreachable from any branch or tag. That safety net isn’t permanent, though: entries referencing unreachable commits expire out of the reflog on a timer (90 days by default) the next time git gc runs, whether gc runs automatically in the background or as part of routine maintenance. A commit you lost weeks ago and only just now realized you need can be gone for good, with no error at the moment it happens – just a reflog that quietly no longer mentions it.
🔎 The Problem
$ git reflog # You expect to see the commit you rewrote away two months ago... # but the entry simply isn't there anymore - no error, no warning # at the time it was pruned, it's just absent from the list now. $ git log --all --source -- path/to/file.cs # Also comes up empty, because the commit is unreachable from any # branch, tag, OR reflog entry - there is no remaining reference # to its SHA anywhere in the local repository at all. # What actually happened, weeks earlier, invisibly: # git gc ran (automatically, as it periodically does) and pruned # every reflog entry older than gc.reflogExpireUnreachable (default # 30 days) that pointed at a commit unreachable from any branch.
✅ Fix: Widen the Reflog Retention Window Before You Need It, Not After
- Set git config gc.reflogExpireUnreachable 180 (or a value matching how long you realistically need to recover work) on any machine where you do a lot of interactive rebasing, amending, or force-pushing, since the default window is shorter than many people assume.
- If a commit is truly critical and you know its SHA, tag it or check it out onto a dedicated branch immediately, rather than relying on the reflog to hold it indefinitely – a real ref never expires the way a reflog entry does.
- Before intentionally rewriting history you might regret, run git log –oneline -5 (or note the SHA) first, so that if you need it back quickly, you’re not depending on reflog search at all.
⚠️ Why This Is Easy to Miss
- Nothing about losing a reflog entry produces an error or a warning at the moment it’s pruned – git gc runs silently and successfully, and the only symptom is a commit that simply can’t be found weeks or months later.
- Most day-to-day recovery stories about the reflog happen within hours of the mistake, which creates a false sense that the reflog is a permanent undo history rather than a retention window with a quiet expiration date.
The reflog isn’t a permanent record – it’s a grace period, and grace periods run out exactly when you’re not looking at the calendar.




