How to name and retrieve a stash by name in git?
This is how you do it:
git stash push -m "my_stash"
Where "my_stash"
is the stash name.
Some more useful things to know: 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
is the index of the stashed change.
Notice that you can apply a stash and keep it in the stack by using the stash name:
git stash apply my_stash_name
git stash save
is deprecated as of 2.15.x/2.16, instead you can use git stash push -m "message"
You can use it like this:
git stash push -m "message"
where "message" is your note for that stash.
In order to retrieve the stash you can use: git stash list
. This will output a list like this, for example:
stash@{0}: On develop: perf-spikestash@{1}: On develop: node v10
Then you simply use apply
giving it the stash@{index}
:
git stash apply stash@{1}
Referencesgit stash man page
If you are just looking for a lightweight way to save some or all of your current working copy changes and then reapply them later at will, consider a patch file:
# save your working copy changesgit diff > some.patch# re-apply it latergit apply some.patch
Every now and then I wonder if I should be using stashes for this and then I see things like the insanity above and I'm content with what I'm doing :)