Hone

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 stash
The work is now a commit, and the tree is clean.
git stash list
One entry, and it names the commit it was made from.
git stash apply
Applied -- and note that the entry is still there.
git stash list
Still one entry. pop would have removed it.
git stash drop
Now the entry is gone. The commit it pointed at is not.
git fsck --unreachable
Objects nothing points at, including the one the stash was.

Your turn

Apply the newest stash but leave it on the list.

git stash 

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.

Practise getting a stash back on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.