Git Stash Apply and Pop: Recover Work Safely
Keep the original while checking
After a short interruption, you want the watering draft back. apply restores changes on the current checkout without removing the stash entry. pop attempts restoration and removes that entry only after success. Both may conflict if the target has changed. Start with a clean target, inspect the entry and check branch and status. An ordinary stash is not tied to restoration on the original branch.
Restore the original staging split
Continue the preceding -u example with a clean tracked working tree. --index attempts to restore the saved staging state as well as file contents. Without it, the original staged/unstaged split is not guaranteed. The expected short status in this fixture is M light.txt, M notes.txt, and ?? draft.txt. The entry remains in the list. Review both diffs and confirm all three files.
git stash listgit stash apply --index "stash@{0}"git status --shortgit diffgit diff --cachedPop and conflicts
In a separate clean fixture containing a stash, run pop once. Do not pop the same entry over the already applied edits above. Successful pop removes that entry, but a conflicting pop leaves it available. A conflict can leave partially applied edits and unmerged index entries. Inspect status and git ls-files -u, resolve the intended content, stage resolved paths and test before considering a drop. There is no git stash --abort command. Do not use a blanket reset to escape a conflict if it could erase valuable work.
Retire a stash only after verification
After apply, you can leave the entry until a verified commit or other durable copy exists. Recheck git stash list because selectors change after another push or drop. git stash drop "stash@{0}" removes the selected entry, not the restored files. git stash branch NAME can restore onto the original base and drops the selected stash on success; this is a useful recovery option, but test it separately. Avoid clear, which removes all entries. Check yourself: does a failed pop mean the workspace is unchanged? No.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Git Stash Apply and Pop: Recover Work Safely — knowledge check
Reason about temporary Git work and recovery.
Which operation keeps the entry after success?
What happens to the entry after a conflicting pop?
Which option attempts to restore the saved index state?
Why inspect status after a failed pop?
When should you drop a stash?