How to fix warning: Log for 'HEAD' only has 5 entries in Git
This warning appears when Git's reflog has fewer entries than expected, typically due to reflog expiration, a freshly cloned repository, or using time-based references beyond the available history.
Quick fix
Fixes warning: Log for 'HEAD' only has 5 entries
git reflog show HEAD- Check current reflog entries
- Use commit-based references instead of time-based
- Use remote tracking for historical references
- Extend reflog retention (optional)
git reflog show HEADwarning: Log for 'HEAD' only has 5 entries
What this error means
When you use a time-based reference in Git like `@{2 days ago}` or `@{1.week.ago}`, Git looks up the commit that a reference (like HEAD or a branch name) pointed to at that time. This lookup uses the **reflog**, which is a local log of when references were updated. The warning "Log for 'HEAD' only has N entries" means the reflog doesn't have enough historical entries to satisfy your time-based query. Git will use the oldest available entry instead, which may not be what you intended. This is important to understand: **reflogs are local and temporary**. They are not part of the repository's shared history and are not transferred during clone, fetch, or push operations. By default, reflog entries older than 90 days are pruned during garbage collection, and unreachable entries (from rebases or amends) expire after just 30 days.
Typical symptoms
- Warning appears when using time-based references like HEAD@{2.weeks.ago}
- Git diff or checkout with @{date} syntax shows unexpected results
- Warning mentions the reflog 'only goes back to' a recent date
- Commands work but may use wrong historical reference
- Issue appears after cloning a repository for the first time
Common causes
- Repository was recently cloned (reflog starts from clone date, not project history)
- Reflog entries have expired due to garbage collection (default: 90 days for reachable, 30 days for unreachable)
- Time reference requested is older than the oldest reflog entry
- Running git gc or git reflog expire pruned historical entries
- Working in a CI/CD environment with fresh checkouts
- The specific ref (branch or HEAD) has limited activity in the reflog
How to fix "warning: Log for 'HEAD' only has 5 entries"
View your reflog to see available entries and their dates:
git reflog show HEADOr with dates:
git reflog show --date=relative HEADThis shows what history is actually available in your reflog.
Instead of time-based references that depend on reflog, use actual commit history:
# Find commits before a date using git log
git log --before="2024-01-15" --oneline -1
# Use git rev-list for scripting
git rev-list -1 --before="2 days ago" HEAD
# Then use the commit hash directly
git diff abc1234..HEADThis queries the actual commit timestamps, which are part of permanent history.
For comparing against historical states, use remote branches:
# Fetch latest remote state
git fetch origin
# Find commit from date on remote
git rev-list -1 --before="Apr 1 2024" origin/main
# Checkout historical state
git checkout $(git rev-list -1 --before="2 weeks ago" origin/main)This works because it queries commit timestamps, not reflog.
To prevent future reflog expiration, configure longer retention:
# Set for current repository
git config gc.reflogExpire "180 days"
git config gc.reflogExpireUnreachable "90 days"
# Or set globally
git config --global gc.reflogExpire "180 days"
git config --global gc.reflogExpireUnreachable "90 days"To keep reflogs indefinitely (not recommended for most cases):
git config gc.reflogExpire never
git config gc.reflogExpireUnreachable neverCheck your current reflog expiration settings:
git config --get gc.reflogExpire
git config --get gc.reflogExpireUnreachableIf these return nothing, default values are in use (90 days and 30 days respectively).
Advanced notes
### Understanding Reflog vs Log
The reflog is fundamentally different from git log:
- git log: Shows the commit history (public, shared, permanent)
- git reflog: Shows when references changed locally (private, local-only, temporary)
When you clone a repository, your reflog is empty except for the clone operation. The commit history via git log goes back to the beginning of the project, but HEAD@{1 year ago} only works if you've had the repo for a year.
### Default Expiration Settings
| Setting | Default | Purpose |
|---------|---------|---------|
| gc.reflogExpire | 90 days | Reachable entries (current branch history) |
| gc.reflogExpireUnreachable | 30 days | Unreachable entries (rebased/amended commits) |
### Pattern-Based Configuration
You can set different expiration for specific refs:
# Never expire remote tracking branches
git config "gc.refs/remotes/*.reflogExpire" never
# Short expiration for stash
git config "gc.refs/stash.reflogExpireUnreachable" "7 days"### Security Considerations
Setting reflog expiration to "never" has implications:
- Repository size grows over time
- Deleted sensitive data remains recoverable locally
- Old commits from rebases are preserved indefinitely
For sensitive repositories, the default expiration helps ensure truly deleted content eventually gets garbage collected.
### CI/CD Environments
In CI/CD pipelines, fresh clones have minimal reflog history. For time-based comparisons, always use:
git rev-list -1 --before="date" origin/branchThis avoids reflog entirely and works reliably in fresh checkouts.
Frequently asked questions
- What does "warning: Log for 'HEAD' only has 5 entries" mean?
- ago}, Git looks up the commit that a reference (like HEAD or a branch name) pointed to at that time. This lookup uses the reflog, which is a local log of when references were updated. The warning "Log for 'HEAD' only has N entries" means the reflog doesn't have enough historical entries to satisfy your time-based query.
- How do I fix "warning: Log for 'HEAD' only has 5 entries"?
- This warning appears when Git's reflog has fewer entries than expected, typically due to reflog expiration, a freshly cloned repository, or using time-based references beyond the available history.
- What causes "warning: Log for 'HEAD' only has 5 entries"?
- Repository was recently cloned (reflog starts from clone date, not project history) Reflog entries have expired due to garbage collection (default: 90 days for reachable, 30 days for unreachable) Time reference requested is older than the oldest reflog entry
- Is the "warning: Log for 'HEAD' only has 5 entries" error serious?
- It is a low-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Git Official Documentation
- ๐Git - git-reflog Documentation(Official Docs)
- ๐Git - git-gc Documentation (gc.reflogExpire settings)(Official Docs)
- ๐ฌ
- ๐ฌKeep Git Reflog Indefinitely? - Stack Overflow(Stack Overflow)
- ๐ฌHow to use git reflog --expire command? - Stack Overflow(Stack Overflow)
- ๐Git Reflog Configuration - Atlassian Git Tutorial(Official Docs)
- ๐Every engineer should understand git reflog - Graphite(Official Docs)
- ๐
- ๐ฌgit reflog | Understanding Git's reflog feature - Initial Commit(Stack Overflow)
- ๐ฌWhat is the Git Reflog? - Git Tower(Stack Overflow)