How to fix warning: Log for 'HEAD' only has 5 entries in Git

GitBEGINNERLOWUpdated Dec 6, 2025ยท 153 views

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
  1. Check current reflog entries
  2. Use commit-based references instead of time-based
  3. Use remote tracking for historical references
  4. Extend reflog retention (optional)
git โ€” error
git reflog show HEAD
warning: 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

  1. Repository was recently cloned (reflog starts from clone date, not project history)
  2. Reflog entries have expired due to garbage collection (default: 90 days for reachable, 30 days for unreachable)
  3. Time reference requested is older than the oldest reflog entry
  4. Running git gc or git reflog expire pruned historical entries
  5. Working in a CI/CD environment with fresh checkouts
  6. The specific ref (branch or HEAD) has limited activity in the reflog

How to fix "warning: Log for 'HEAD' only has 5 entries"

1Check current reflog entries

View your reflog to see available entries and their dates:

bash
git reflog show HEAD

Or with dates:

bash
git reflog show --date=relative HEAD

This shows what history is actually available in your reflog.

2Use commit-based references instead of time-based

Instead of time-based references that depend on reflog, use actual commit history:

bash
# 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..HEAD

This queries the actual commit timestamps, which are part of permanent history.

3Use remote tracking for historical references

For comparing against historical states, use remote branches:

bash
# 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.

4Extend reflog retention (optional)

To prevent future reflog expiration, configure longer retention:

bash
# 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):

bash
git config gc.reflogExpire never
git config gc.reflogExpireUnreachable never
5Verify configuration

Check your current reflog expiration settings:

bash
git config --get gc.reflogExpire
git config --get gc.reflogExpireUnreachable

If 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:

bash
# 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:

bash
git rev-list -1 --before="date" origin/branch

This 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