stash is a very powerful concept, it’s like Harry Potter’s Room of Requirement for your code, you throw it in here and you can get it back when you need it again in the future.
But dealing with it can be dangerous.
git stash pop throws away the stash after applying it.
git stash apply leaves it in the stash list and can be reused later (or dropped using
git stash drop)
note: If during a
popthere are conflicts it behave exactly like git stash apply and the stash will not be lost
git stash pop is equivalent to
git stash apply && git stash drop
git stash apply can be a life-saver somethimes when you mess up with taking something from the stash
image credit: ancientking
Top comments (5)
I never considered the possibility of the git stash filling up like a messy desktop or the attempted fix: 'new folder'. In that respect, I sort of prefer git stash pop, otherwise retrieval could retrieve and open a Pandora's Box of forgotten code snippets.
I'd rather git-spring-cleaning once in a while, finding something in the stashes is much easier than retrieve a stash dropped by mistake.
Better safe than sorry 😁
Great tip, super ...
My rule is never leave work with objects in stash.
Other than the auto stash, why stash over a WIP commit?
It is much easier to retrieve a missing commit than a missing stash