Recovering from a Bad Reset --hard
Three real commits. One destructive reset. Recovered in a single command.
git reset --hard HEAD~3 is a real, genuinely destructive command — it moves the branch pointer back three commits and overwrites the working directory to match, with no confirmation. Three real recipes, just committed, disappear from the branch instantly.\n\nBut reset --hard, like every ref-moving command, is itself recorded in reflog before it happens. HEAD@{1} always means "wherever HEAD was, one real step before its most recent move" — which, immediately after a bad reset, is exactly the good state from right before it. No searching required.
A Real, Destructive Mistake
git reset --hard HEAD~3
Three real commits, instantly gone from the branch — no confirmation, no warning. The working directory is overwritten to match, too.
The One-Command Undo
git reset --hard HEAD@{1}
HEAD@{1} means "one real step back in HEAD's own reflog" — immediately after the bad reset, that is exactly the good commit from right before it. No hash to look up, no grep required.
Confirming the Real Recovery
git log --oneline -4
All three real commits, back exactly where they were, plus whatever came before them.
HEAD@{1}
Reflog's own relative addressing — "one real step back from HEAD's current reflog position," regardless of what kind of operation caused that move. Confirmed directly in this lab: run immediately after a bad reset --hard, it pointed exactly at the good state from right before it.
🍲 Three Real New Commits
Three genuine recipes, committed normally.
cd ~/team-recipes && echo 'Slow Cooker Chili' > slow-cooker-chili.md && git add slow-cooker-chili.md && git commit -m 'Add slow cooker chili recipe'cd ~/team-recipes && echo 'Instant Pot Risotto' > instant-pot-risotto.md && git add instant-pot-risotto.md && git commit -m 'Add instant pot risotto recipe'cd ~/team-recipes && echo 'Air Fryer Fries' > air-fryer-fries.md && git add air-fryer-fries.md && git commit -m 'Add air fryer fries recipe'cd ~/team-recipes && git log --oneline -3student@lab:~$ cd ~/team-recipes && echo 'Slow Cooker Chili' > slow-cooker-chili.md && git add slow-cooker-chili.md && git commit -m 'Add slow cooker chili recipe' [master fe046b3] Add slow cooker chili recipe 1 file changed, 1 insertion(+) create mode 100644 slow-cooker-chili.md student@lab:~$ cd ~/team-recipes && echo 'Instant Pot Risotto' > instant-pot-risotto.md && git add instant-pot-risotto.md && git commit -m 'Add instant pot risotto recipe' [master c21a8c2] Add instant pot risotto recipe 1 file changed, 1 insertion(+) create mode 100644 instant-pot-risotto.md student@lab:~$ cd ~/team-recipes && echo 'Air Fryer Fries' > air-fryer-fries.md && git add air-fryer-fries.md && git commit -m 'Add air fryer fries recipe' [master 7b452aa] Add air fryer fries recipe 1 file changed, 1 insertion(+) create mode 100644 air-fryer-fries.md student@lab:~$ cd ~/team-recipes && git log --oneline -3 7b452aa (HEAD -> master) Add air fryer fries recipe c21a8c2 Add instant pot risotto recipe fe046b3 Add slow cooker chili recipe
💥 The Bad Reset
A real, destructive reset --hard, three commits back.
cd ~/team-recipes && git reset --hard HEAD~3cd ~/team-recipes && git log --oneline -3student@lab:~$ cd ~/team-recipes && git reset --hard HEAD~3 HEAD is now at 536a53d Include the filename in check-times.sh's failure message student@lab:~$ cd ~/team-recipes && git log --oneline -3 536a53d (HEAD -> master) Include the filename in check-times.sh's failure message 529c9c2 Add saffron rice recipe e8bb77f Rename roast-chicken.md to oven-roast-chicken.md for clarity
⏪ Recover in One Command
HEAD@{1} means exactly "right before that last move."
cd ~/team-recipes && git reflog | head -5cd ~/team-recipes && git reset --hard HEAD@{1}cd ~/team-recipes && git log --oneline -4student@lab:~$ cd ~/team-recipes && git reflog | head -5 536a53d HEAD@{0}: reset: moving to HEAD~3 7b452aa HEAD@{1}: commit: Add air fryer fries recipe c21a8c2 HEAD@{2}: commit: Add instant pot risotto recipe fe046b3 HEAD@{3}: commit: Add slow cooker chili recipe 536a53d HEAD@{4}: checkout: moving from master to master student@lab:~$ cd ~/team-recipes && git reset --hard HEAD@{1} HEAD is now at 7b452aa Add air fryer fries recipe student@lab:~$ cd ~/team-recipes && git log --oneline -4 7b452aa (HEAD -> master) Add air fryer fries recipe c21a8c2 Add instant pot risotto recipe fe046b3 Add slow cooker chili recipe 536a53d Include the filename in check-times.sh's failure message
Lab 3.4.3 complete. A real, destructive reset, undone in a single command:\n\n\n 3 real commits : ✅ made\n reset --hard HEAD~3 : ✅ genuinely discarded them\n reset --hard HEAD@{1} : ✅ fully recovered, one command\n
Enable JavaScript to run the live terminal and track your progress.