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 which 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.
Retrieve Stashed Changes To retrieve changes out of the stash and apply them to the current branch you're on, you have two options: git stash apply STASH-NAME applies the changes and leaves a copy in the stash. git stash pop STASH-NAME applies the changes and removes the files from the stash.
To stash a specific file, use the “git stash push” command and specify the file you want to stash. However, the other tracked files that may be modified in your current working directory are untouched.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With