C · RecoverAdvanced40 min read
8. reflog, reset & recovery
Git & GitHub · 48 pages source format
reflog records HEAD movements — undo "disasters." reset --soft/mixed/hard — know blast radius before using.
What you'll learn
- git reflog
- reset --soft/mixed/hard
- Recovering "lost" commits
- cherry-pick lite
reflog is your safety net
git reflog shows where HEAD was. git reset --hard HEAD@{1} goes back — if you act before GC.
git commit -m "important work"
git reset --hard HEAD~1
git reflog
# find lost commit hash
git reset --hard abc1234Do this now
Make commit, reset --hard HEAD~1, panic, reflog, recover.
Clear?
Reset modes
--soft: keep staging and working tree. --mixed (default): keep working tree. --hard: destroy changes.
Do this now
Try --soft reset: commit undone but changes still staged.
Pro tip. --hard is destructive — use only in throwaway repos or when certain.
Clear?
cherry-pick
git cherry-pick <hash> applies one commit elsewhere. Useful for hotfixes.
Do this now
Cherry-pick a commit from feature branch onto main in practice repo.
Clear?