Rescuing Work with the Reflog and Stash
Master Git's safety nets: use the reflog to recover from bad resets and rebases, and use the stash to safely set aside and restore in-progress work during recovery.
Rescuing Work with the Reflog and Stash is a free Git Advanced: Monorepo, Submodules & Workflows lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Git Advanced: Monorepo, Submodules & Workflows learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Git Rarely Loses Data
It feels like a bad reset or rebase destroys work, but Git almost never truly loses commits. They become unreachable, not deleted, and remain recoverable for weeks.
The reflog is your map back to them.
What the Reflog Records
The reflog logs every move of HEAD and branch tips: commits, checkouts, resets, rebases, merges. It is local and not shared, a private diary of where your refs have been.
git reflog
# a1b2c3d HEAD@{0}: reset: moving to HEAD~3
# 9f8e7d6 HEAD@{1}: commit: add featureRecovering After a Bad Reset
Ran git reset --hard and lost commits? Find the pre-reset SHA in the reflog and reset back to it.
git reflog
git reset --hard HEAD@{1}Recovering After a Bad Rebase
A rebase rewrites commits. If it went wrong, the reflog still holds the pre-rebase tip. Point your branch back at it.
git reflog
git reset --hard HEAD@{5} # the entry just before 'rebase'Restoring a Single Lost Commit
You do not always want to reset the whole branch. To resurrect just one commit, cherry-pick its SHA from the reflog.
git cherry-pick 9f8e7d6The Stash as a Safety Net
Before risky recovery operations, save uncommitted work with git stash. It tucks changes away cleanly so you can experiment without losing them.
git stash push -m 'wip before recovery'Inspecting and Restoring Stashes
List stashes and bring one back. apply keeps it in the list; pop restores and removes it.
git stash list
git stash show -p stash@{0}
git stash pop stash@{0}Recovering Dropped Stashes
Dropped a stash by mistake? Stashes are commits too. Find the dangling commit and re-apply it.
git fsck --no-reflogs | grep commit
git stash apply <dangling-sha>Finding Orphans with fsck
When even the reflog does not show it, git fsck --lost-found hunts for dangling commits and blobs, the last-resort recovery tool.
git fsck --lost-foundThe Garbage Collection Clock
Unreachable objects survive until garbage collection prunes them, by default after about 30 days for reflog entries. Recover promptly; do not let weeks pass before you go looking.
The Reflog Is Local Only
Remember: the reflog lives only in your clone. A teammate's reflog will not show your moves, and a fresh clone has none. If you need shared recoverability, push branches or tags before risky operations.
Quick Check
Test your understanding of Git recovery tools.
Recap
You learned Git's safety nets: the reflog recovers from bad resets and rebases, cherry-pick restores single lost commits, the stash protects work-in-progress, fsck hunts dangling objects, and the GC clock means you should recover promptly. Git rarely loses data if you know where to look.
Frequently asked questions
Is the “Rescuing Work with the Reflog and Stash” lesson free?
Yes — the full text of “Rescuing Work with the Reflog and Stash” is free to read here on the web, and the Git Advanced: Monorepo, Submodules & Workflows course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Git Advanced: Monorepo, Submodules & Workflows course, upgrade to CoddyKit PRO.
What will I learn in “Rescuing Work with the Reflog and Stash”?
Master Git's safety nets: use the reflog to recover from bad resets and rebases, and use the stash to safely set aside and restore in-progress work during recovery. You practise Git Advanced: Monorepo, Submodules & Workflows with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Git Advanced: Monorepo, Submodules & Workflows?
No prior experience is required. Git Advanced: Monorepo, Submodules & Workflows on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Rescuing Work with the Reflog and Stash” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Git Advanced: Monorepo, Submodules & Workflows lesson?
Yes. Every Git Advanced: Monorepo, Submodules & Workflows lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Recovering Lost Commits and Branches
- Debugging with Git Bisect
- Optimizing Git Repository Performance
- Rescuing Work with the Reflog and Stash