DEV Community

Jaga santagostino
Jaga santagostino

Posted on • Originally published at jagascript.com on

18 4

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay