Your safety net. Almost everything you 'lost' is in here.
git reflog records every move of every ref tip — commits, resets, rebases, checkouts, the works. It's your local, private, time-travel log and the single most important recovery tool in Git.
Branches are pointers. The reflog is the history of where each pointer has been. Even a reset --hard to oblivion leaves a breadcrumb here for ~90 days.
git reflog [show] [<options>] [<ref>]
git reflog expire [--expire=<time>] [--expire-unreachable=<time>]
[--rewrite] [--updateref] [--stale-fix] [--all|<refs>...]
git reflog delete <ref>@{<specifier>}...
git reflog exists <ref>| Flag | What it does |
|---|---|
--all | Operate on reflogs of every ref, not just HEAD. |
--expire=<time> | Drop entries older than <time> (default 90 days, gc.reflogExpire). |
--expire-unreachable=<time> | Drop unreachable entries older than <time> (default 30 days). |
-n <num> | Limit show output. |
--date=<format> | Format timestamps: relative, iso, short, ... |
git reflog expire --expire=now --all | ⚠️ Wipes your safety net. Combined with gc --prune=now, recovery is over. |
git reflog show mastergc runs this for you.git reflog expire --expire=30.days --all<ref>@{n} selector.git reflog delete HEAD@{2}<ref>. Useful in scripts.git reflog exists refs/heads/topicreset --hard — git reset --hard HEAD@{1} brings it back.git reflog and git branch <name> <sha>.git reflog shows the pre-rebase HEAD; reset to it.git reflog
git reset --hard HEAD@{1}git reflog --all | grep my-branch
git branch my-branch <sha-from-reflog>git reflog --date=isogit config core.logAllRefUpdates truereset --hard, rebase, or filter-branch: note git rev-parse HEAD. Belt and braces.core.logAllRefUpdates = true (the default for non-bare repos). Disabling it to save bytes is penny-wise, pound-foolish.core.logAllRefUpdates = false by default — no reflog, no safety net on the server.git gc prunes expired reflog entries and then unreachable objects. After 90 days, that emergency commit may genuinely be gone.HEAD@{2} and master@{2} are different — @{N} means the Nth prior position of that specific ref, not the Nth global reflog entry.Hit each option, then Check answers. Score is recorded; Next is always open.