Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Revisions and Pathspecs

Reflog names: @{n} and @{date}

Reference for Git reflog revision syntax: HEAD@{2}, main@{yesterday}, main@{2 hours ago}, @{-1} for the previous branch, and what expires from the reflog.

Every time a branch tip or HEAD moves, Git appends a line to that ref's reflog. The suffix @{...} reads from it. HEAD@{2} means "where HEAD was two moves ago", and main@{yesterday} means "where main pointed yesterday on this computer". These names are how you find a commit after a bad reset, an amended commit or a rebase.

The reflog is local and temporary. It records what happened in your clone, not in the project history, and old entries expire (90 days for reachable entries, 30 for unreachable ones, by default).

Terminal
git show HEAD@{1}                 # previous position of HEAD
git diff main@{yesterday} main    # what changed on main since yesterday
git switch -                      # same as git switch @{-1}

Try it

Bash Steps back in the reflog

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Time-based names and the previous branch

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
<ref>@{<n>}            # n-th previous value of <ref> (0 = current)
@{<n>}                 # same, for the current branch
HEAD@{<n>}             # n-th previous value of HEAD
<ref>@{<date>}         # value of <ref> at that time
@{-<n>}                # the branch checked out n checkouts ago
Form Meaning
main@{0} Where main is now. @{0} is the current branch tip.
main@{3} The value of main three reflog entries ago.
HEAD@{3} Where HEAD was three moves ago, whatever branch it was on.
main@{yesterday}, main@{1.week.ago}, main@{2 hours ago} Relative times. Anything the date parser understands works.
main@{2026-03-03 12:00} An absolute time, in your time zone unless one is given.
@{-1} The branch you were on before the last git checkout/git switch. @{-2} is the one before that.
- In git switch -, git checkout -, git merge - and a few other commands, shorthand for @{-1}.

Errors: an index beyond the end of the reflog gives fatal: log for 'main' only has N entries (when the branch exists). A date earlier than the first entry gives a warning log for 'main' only goes back to <date> and uses the oldest value.

Usage notes

  • @{n} counts moves, not commits. A single git pull can add several entries; git rebase adds one for every replayed commit. Use git reflog to see numbers next to descriptions before you pick one.
  • Per-ref logs. HEAD and each branch have separate reflogs. HEAD@{1} follows every checkout and commit; main@{1} only follows changes to main.
  • Dates mean "on this machine". main@{last.week} is not about the project history. It asks what your own main pointed to then. In a fresh clone the answer is the oldest value, with a warning.
  • @{-n} is special. It reads the HEAD reflog for checkout messages ("moved from X to Y"), so it is a branch name, not a commit hash. Unlike the other forms it is usable with git branch -d @{-1}.
  • Expiry and gc. gc.reflogExpire (default 90 days) and gc.reflogExpireUnreachable (30 days) remove old entries. Setting core.logAllRefUpdates to false turns reflogs off. Bare repositories have no reflogs by default.
  • Reflogs are never shared. Neither git push nor git clone copies them.
  • Do not confuse with @{upstream}. That is a different @{...} form, covered in @{upstream} and @{push}.
  • Quote the braces in shells. Bash and PowerShell treat {} specially in some contexts; write 'HEAD@{1}'.