I had some uncommitted changes in my development branch and I stashed them using git stash
, but there were some changes which were very important among those stashed ones. Is there any way to get back those changes?
Also, I have made some changes on top of the stashed code files since.
Is there any chance I can retrieve the stashed changes to a new branch if possible?
To make this simple, you have two options to reapply your stash:
git stash pop
- Restore back to the saved state, but it deletes the stash from the temporary storage.git stash apply
- Restore back to the saved state and leaves the stash list for possible later reuse.You can read in more detail about git stashes in this article.
git stash pop
will get everything back in place
as suggested in the comments, you can use git stash branch newbranch
to apply the stash to a new branch, which is the same as running:
git checkout -b newbranch
git stash pop
To check your stash content :-
git stash list
apply a particular stash no from stash list:-
git stash apply stash@{2}
or for applying just the first stash:-
git stash pop
Note: git stash pop will remove the stash from your stash list whereas git stash apply wont. So use them accordingly.
On mac this worked for me:
git stash list(see all your stashs)
git stash list
git stash apply (just the number that you want from your stash list)
like this:
git stash apply 1
you can stash the uncommitted changes using "git stash" then checkout to a new branch using "git checkout -b " then apply the stashed commits "git stash apply"
Source: Stackoverflow.com