DEV Community

How to Git Stash Your Work [the Correct Way]

Nesha Zoric on May 15, 2018

Imagine that you are working on a part of a project and it starts getting messy. There has been an urgent bug that needs your immediate attention. ...
Collapse
 
peterhric profile image
Peter Hric

I have 1 stash item @{0}
What in the world is the correct syntax to drop it ?
I tried everything possible and impossible, everything is incorrect.
Just one WORKING example, please...

Collapse
 
peterhric profile image
Peter Hric

git stash drop stash@{0}

phew !

I wonder why did they not over complicate it even more:

git stash drop sT4Sh@#$%&(^___{oo)oo}}]]&%&^

Collapse
 
nefira profile image
Nefira

Hello Peter,

Might depend on your version of git, but I think you could use a simpler command such as :

git stash drop 0 (in your precise case, otherwise, replace 0 by the stash id.

This is in fact what is written in the article, but either it wasn't easy to understand without an example, or you have some special configuration of git ? On my machine at least, it works.

Thread Thread
 
nefira profile image
Nefira

I should even add that if you want to delete the last created stash (stash@{0}), you could even just type : git stash drop. But again, that is assuming that you have a default git configuration (I am not too familiar with all the configuration options available). Hope that helps.

Thread Thread
 
peterhric profile image
Peter Hric

Thank you - now I see, GIT indeed is a tool for experts :)

Collapse
 
smw7156 profile image
shadman

I have couple of stash
stash@{0}
stash@{1}
stash@{2}
stash@{3}

Now I want my next commit to contain the changes of both stash@{1} and stash@{2} .
How can I apply multiple stash (except the top one i.e. stash@{0} ) ?

Collapse
 
smw7156 profile image
shadman

It was simple. Just applying both the stash
git stash apply stash@{1}
git stash apply stash@{2}
Just make sure that you don't have any changes in the same line

Collapse
 
mateenkhan profile image
Mateen

Thanks for the info!

Collapse
 
peterhric profile image
Peter Hric

git stash drop stash@{0}
Super complicated and verbose like everything "made-in-git"
Git is a tool for experts..=> crap

Collapse
 
pierre profile image
Pierre-Henry Soria ✨

Great and clear explanation 👌