Sub topic 12
What the reflog cannot bring back
This chapter assumes you can read git reflog output, use HEAD@{n} selectors, and have recovered a commit after git reset --hard. The reflog is a safety net with holes. Knowing where they are tells you when to stop searching and what to try next.
The reflog is local and per repository
The reflog lives in your own clone, under .git/logs. It is never pushed or fetched. A fresh clone starts with almost no history, and a teammate's reflog cannot help you.
Deleting the repository directory also deletes the reflog. If you re-clone, commits that existed only in the old clone are gone unless you copied the directory first.
Uncommitted changes are not recorded
The reflog records movements of references. Git writes those entries when a commit exists. Changes that were never committed have no entry.
This matters most with git reset --hard and git checkout -- <file>. Both overwrite the working tree. The reflog can restore commits you discarded, but not edits you had not committed.
echo "draft" >> notes.txt
git reset --hard HEAD
git reflog -1The file edit is gone. The reflog shows only the reset itself, and no commit contains the draft.
Files you staged with git add are a partial exception. Git stores their contents as blob objects, so git fsck --lost-found may still find them. Plain unstaged edits are not stored at all.
Entries expire
Git removes old reflog entries during garbage collection. The defaults are:
| Setting | Default | Applies to |
|---|---|---|
| `gc.reflogExpire` | 90 days | Entries whose commit is still reachable from the ref |
| `gc.reflogExpireUnreachable` | 30 days | Entries whose commit is no longer reachable from the ref |
The 30-day window is the one that matters for recovery. A commit you discarded with a hard reset counts as unreachable, so its entry can vanish after about 30 days.
You can check or change the values:
git config --get gc.reflogExpireUnreachable
git config gc.reflogExpireUnreachable "90 days"After an entry expires, git gc may delete the commit object itself. Once the object is deleted, no command can bring it back.
Manual cleanup removes the safety net
Some commands drop entries on purpose. Running git reflog expire --expire=now --all followed by git gc --prune=now deletes unreachable commits immediately. Do not run them while you might still want something back.
Likewise, git reflog delete <selector> removes a single entry.
Operations that do not leave a path back
The reflog tracks references. Some losses do not involve a reference at all:
- Files ignored by
.gitignorewere never tracked, so Git has no copy of them. git clean -fddeletes untracked files, and Git has no copy.- A branch created and deleted in another clone leaves nothing in yours.
- A force-push overwrites the remote branch. Your local reflog may still hold the old tip, but the remote's reflog (if any) is not yours to read.
Choosing the next step
When the reflog has no useful entry, work through these checks in order:
- Run
git reflog show <branch>for the branch itself, not onlyHEAD. - Look at
ORIG_HEADwithgit rev-parse ORIG_HEAD. - Run
git fsck --lost-foundto list dangling commits that no reference reaches. - Check other copies: a teammate's clone, a CI checkout, or the remote.
- Check your editor's local history for uncommitted work.
Exercise
You ran git reset --hard HEAD~3 six weeks ago and only now realize you need those commits. Your configuration is the default. Is git reflog likely to still list them, and what should you try if it does not?
Show answer
Probably not. The discarded commits became unreachable, and the default gc.reflogExpireUnreachable is 30 days, so their entries were likely expired. Try git fsck --lost-found to find dangling commits, because the objects may survive until garbage collection prunes them. If that fails, check other clones or the remote.