Manuals / Git & GitHub / Chapter 8

C · Recover · advanced · Day 6 · Chapter 8 of 12

reflog, reset & recovery

reflog records HEAD movements — undo "disasters." reset --soft/mixed/hard — know blast radius before using.

Path progress
61%

Step 1 of 3

reflog is your safety net

git reflog shows where HEAD was. git reset --hard HEAD@{1} goes back — if you act before GC.

reflog is your safety netDrag stickies · tap for tips
Study mapDrag stickies · tap for tipsKeep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Assert the UIdrag · tap →Retry wiselydrag · tap →Seed datadrag · tap →Close the loopdrag · tap →Keep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Pathwise hackdrag · tap →reflog is your safdrag · tap →Try thisdrag · tap →Follow the dashed drag · tap →

Example

git commit -m "important work"
git reset --hard HEAD~1
git reflog
# find lost commit hash
git reset --hard abc1234

Do this now

Make commit, reset --hard HEAD~1, panic, reflog, recover.

Was this step clear?
Chapter learning outcomes
  • git reflog
  • reset --soft/mixed/hard
  • Recovering "lost" commits
  • cherry-pick lite

Clear these before you leave

Side quest

Disaster drill

Script: commit → bad reset → recover via reflog. Time yourself.