Lessons · Git · getting a stash back
Getting a stash back
A stash is a commit. The stash list is a set of pointers to those commits, so dropping one removes the pointer and leaves the commit where it was.
Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.
What it is for
pop deletes the entry as it applies it, and the moment you find out the result was wrong is the moment after that.
How to think about it
Prefer apply while you are unsure -- it leaves the entry on the list. If you have already dropped one, it is an unreachable commit like any other.
Worked example
git stashThe work is now a commit, and the tree is clean.
git stash listOne entry, and it names the commit it was made from.
git stash applyApplied -- and note that the entry is still there.
git stash listStill one entry. pop would have removed it.
git stash dropNow the entry is gone. The commit it pointed at is not.
git fsck --unreachableObjects nothing points at, including the one the stash was.
Your turn
Apply the newest stash but leave it on the list.
git stash
Try it in a real repository
The trap
Popping onto the wrong branch, seeing conflicts, and assuming the stash is gone. A conflicting pop leaves the entry in place on purpose.