By admin , 29 April 2026

Synopsis

git reflog [show] [<ref>]
git reflog expire [--expire=<time>] [--all]
git reflog delete <entry>

Description

The git reflog command shows the history of where each ref (HEAD, branches) has pointed locally. Every move — commit, checkout, reset, rebase — is logged with a timestamp and reason. The reflog is your safety net: even after a "destructive" operation like git reset --hard, the previous state is recoverable for as long as the reflog entry survives (typically 90 days).

Refs in the reflog are addressable as HEAD@{2} ("HEAD's value 2 moves ago") or HEAD@{2.hours.ago}. To recover a "lost" branch, find its old SHA in the reflog and create a new branch from it.

In day-to-day use, git reflog integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git reflog --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.

Understanding how git reflog interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git reflog's side effects helps avoid all three.

Common Options

Option / SubcommandDescription
show <ref>Display reflog for a ref (default HEAD).
expirePrune old entries.
--expire=<time>Expire entries older than this.
--expire-unreachable=<time>For commits unreachable from any ref.
--allOperate on every ref.
delete <entry>Remove a single entry.

Examples

git reflog
# Recent moves of HEAD

git reflog show feature/api
# Just the feature branch's history

git reset --hard HEAD@{1}
# Recover from a wrong reset by going back one move

git reflog expire --expire=30.days --all
# Trim reflog to last 30 days for every ref

Common Mistakes

Reflogs are LOCAL only — fetching from a remote does not include their reflog. Reflog entries expire eventually; don't rely on them for long-term recovery. Running git gc --prune=now after expiring the reflog can permanently remove unreachable commits.

Related Commands

git reset, git rebase, git fsck, git gc