advanced

Reflog

Recover recently moved references after reset, rebase, branch deletion, or other local history operations.

Reflog records **local** movements of refs (HEAD, branch tips). It is the recovery journal after reset, rebase, checkout, or branch deletion — commits may still exist even when no branch points to them.

					git reflog
git reflog show feature/login
git switch -c recover HEAD@{3}
				

Entries expire after Git's garbage collection (default ~90 days for unreachable commits). Reflog does not exist on the remote — server-side recovery needs other backups.

On interviews: reflog is local-only, time-limited, and how to create a recovery branch from `HEAD@{n}`.

Common pitfalls: running aggressive cleanup before recovery; assuming reflog replaces remote backups; confusing reflog with `git log`.

The trade-off is powerful local recovery versus no guarantee after GC or on another machine.

Checklist:

  • Inspect reflog immediately after accidental reset/rebase.
  • Create a named recovery branch before further destructive ops.
  • Push recovery branch if the work must survive locally.
  • Do not rely on reflog for shared disaster recovery.