Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git stash apply version

Tags:

git

git-stash

I have 2 branches: master | design

Working in design I did a stash and switched to master, made some adjustments. Switched back to design and did a stash apply only to lose all my changes in the design branch.

I am hoping all my work is within a stash as I have not cleared or removed these.

If I do a stash list I get 4 results:

stash@{0}: WIP on design: f2c0c72... Adjust Password Recover Email stash@{1}: WIP on design: f2c0c72... Adjust Password Recover Email stash@{2}: WIP on design: eb65635... Email Adjust stash@{3}: WIP on design: eb65635... Email Adjust 

If I try git stash apply f2c0c72 I am getting an error:

fatal: Needed a single revision f2c0c72: no valid stashed state found 

How can I apply a specific stash?

like image 599
Lee Avatar asked Dec 15 '09 20:12

Lee


People also ask

What is git stash apply?

git stash temporarily shelves (or stashes) changes you've made to your working copy so you can work on something else, and then come back and re-apply them later on.

How do you apply 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 pop a specific stash in git?

To pop a specific stash in git, you can use the git stash apply command followed by the stash@{NUMBER} command.


1 Answers

The keys into the stash are actually the stash@{n} items on the left. So try:

git stash apply stash@{0} 

(note that in some shells you need to quote "stash@{0}", like zsh, fish and powershell).

Since version 2.11, it's pretty easy, you can use the N stack number instead of using stash@{n}. So now instead of using:

git stash apply "stash@{n}" 

You can type:

git stash apply n 

To get list of stashes:

git stash list 

In fact stash@{0} is a revision in git that you can switch to... but git stash apply ... should figure out how to DTRT to apply it to your current location.

like image 163
araqnid Avatar answered Oct 01 '22 05:10

araqnid