Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to name and retrieve a stash by name in git?

Tags:

git

git-stash

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.

like image 483
Suan Avatar asked Jun 29 '12 21:06

Suan


People also ask

How do I retrive git stash?

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.

How do I find a specific file from a git 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.


1 Answers

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 
like image 118
Sri Murthy Upadhyayula Avatar answered Sep 23 '22 07:09

Sri Murthy Upadhyayula