DEV Community

Jaga santagostino
Jaga santagostino

Posted on • Originally published at jagascript.com on

don't use git stash pop

room-of-requirement

Why?

A git 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.

Running 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 pop there are conflicts it behave exactly like git stash apply and the stash will not be lost

Worth notice

git stash pop is equivalent to git stash apply && git stash drop

Conclusion

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)

Collapse
 
sally profile image
Sally

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.

Collapse
 
jaga profile image
Jaga santagostino

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 😁

Collapse
 
leob profile image
leob

Great tip, super ...

Collapse
 
felipe1982 profile image
Felipe Alvarez

My rule is never leave work with objects in stash.

Collapse
 
shhac profile image
Paul Somers

Other than the auto stash, why stash over a WIP commit?

It is much easier to retrieve a missing commit than a missing stash