Explore Courses Blog Tutorials Interview Questions
+6 votes
in DevOps and Agile by (29.3k points)

I was always under the impression that you could give a stash a name by doing git stash save stashname, which you could, later on, apply by doing git stash apply stashname. But it seems that in this case, all that happens is that stashname will be used as the stash description.

Is there no way to actually name a stash? If not, what would you recommend to achieve equivalent functionality? Essentially I have a small stash that I would periodically like to apply, but don't want to always have to hunt in git stash list what its actual stash number is.

2 Answers

+4 votes
by (50.2k points)

As per git versions 2.15, this command git stash save is deleted and instead of that now we have

git stash push -m "message"

The message is the note of push

And if you need to retrieve you can use git stash list this will give you a list as output 

For example:

stash@{0}: On develop: perf-spike

stash@{1}: On develop: node v10

Then for retrieving you just need to do an apply with stash@{index}

For example:

git stash apply stash@{1}


+9 votes
by (62.9k points)

This is how you do it:

git stash save "my_stash"

Where "my_stash" is the stash name. Remember that all the stashes are stored in a stack. Type:

git stash list

This will list down all your stashes.

To apply a stash and remove it from the stash stack, type:

git stash pop stash@{n}

To apply a stash and keep it in the stash stack, type:

git stash apply stash@{n}

Where n represents the index of the stashed change.

Related questions

Browse Categories