This error occurs when Git cannot find the reflog entry you referenced. Reflog entries expire after 90 days by default, or the reference may have been garbage collected.
The `HEAD@{n}` syntax refers to the nth previous position of HEAD as recorded in Git's reflog. When you see "fatal: bad revision 'HEAD@{10}'", it means Git cannot find that specific reflog entry. The reflog (reference log) is a local record of where your HEAD and branch tips have pointed over time. It's like an undo history for your repository. However, reflog entries are not permanent - by default, Git expires entries older than 90 days for reachable commits and 30 days for unreachable commits. This error commonly appears when trying to recover old commits using `git reset`, `git checkout`, or `git show` with a reflog reference that no longer exists. Unlike regular Git history, the reflog is purely local and is not shared through pushes, fetches, or clones.
First, see what reflog entries actually exist:
git reflogThis shows all available HEAD positions. If your desired entry isn't listed, it has likely expired. Note the highest index number available - you cannot reference beyond this.
Check when entries expire to understand the timeline:
git reflog --date=relativeOr with absolute dates:
git reflog --date=isoEntries older than 90 days (reachable) or 30 days (unreachable) may be expired.
If reflog entries are gone, use git fsck to find orphaned commits:
git fsck --lost-foundThis lists dangling commits, blobs, and trees. Look through the output for commits:
git show <commit-hash>Once you find the commit you need, recover it:
git checkout -b recovered-branch <commit-hash>Each branch has its own reflog. Try accessing the branch reflog instead:
git reflog show main
git reflog show <branch-name>You can reference these as main@{n} instead of HEAD@{n}.
If you know the commit hash from CI logs, IDE history, or elsewhere:
# View the commit
git show <commit-hash>
# Create a branch from it
git checkout -b recovered-branch <commit-hash>
# Or reset your current branch to it
git reset --hard <commit-hash>Increase reflog expiration times to keep entries longer:
# Keep reachable reflog entries for 1 year
git config --global gc.reflogExpire "365 days"
# Keep unreachable reflog entries for 180 days
git config --global gc.reflogExpireUnreachable "180 days"To never expire reflog entries (use with caution - consumes disk space):
git config --global gc.reflogExpire never
git config --global gc.reflogExpireUnreachable never## Reflog Expiration Configuration
Git has two configuration settings controlling reflog expiration:
- `gc.reflogExpire`: Time to keep entries for commits reachable from current branch tips (default: 90 days)
- `gc.reflogExpireUnreachable`: Time to keep entries for unreachable commits (default: 30 days)
You can set pattern-specific expiration with gc.<pattern>.reflogExpire, for example:
# Keep stash reflog forever
git config gc.refs/stash.reflogExpire never## When Garbage Collection Runs
Reflog entries are pruned when git gc runs, which happens:
- Automatically via git gc --auto (triggered by various Git operations)
- Manually when you run git gc
- During git repack operations
To check current settings:
git config --get gc.reflogExpire
git config --get gc.reflogExpireUnreachable## Manual Reflog File Access
The reflog is stored in plain text at .git/logs/HEAD and .git/logs/refs/heads/<branch>. In emergencies, you can read these files directly:
cat .git/logs/HEAD## Time-Based Reflog Syntax
Instead of numeric indices, you can use time-based references:
git show HEAD@{yesterday}
git show HEAD@{2.weeks.ago}
git show main@{2024-01-15}These still depend on reflog entries existing for that timeframe.
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server
fatal: unable to access: Proxy auto-configuration failed
How to fix 'Proxy auto-configuration failed' in Git
fatal: unable to access: Authentication failed (proxy requires basic auth)
How to fix 'Authentication failed (proxy requires basic auth)' in Git
fatal: unable to access: no_proxy configuration not working
How to fix 'no_proxy configuration not working' in Git
fatal: unable to read tree object in treeless clone
How to fix 'unable to read tree object in treeless clone' in Git