how to get the stash back after pulling

84.7k views Asked by At

Yesterday I made some changes on the master branch but didn't commit them, today I tried to pull the master but it said I have to commit or stash my changes Please, commit your changes or stash them before you can merge. I stashed them git stash and then pulled from master git pull now I have done some changes in my code but figured out that should have done the stash and i had to commit the changes. Now what can I do to have

1) the changes from stash back

2) what I got from git pull

3) and my current changes

I found this post here but the person hadn't pulled from master, so I am not sure the answers there would work for me and cannot really risk it and try as it is on master.

2

There are 2 answers

3
Vampire On BEST ANSWER

Just use git stash pop or git stash apply. As long as the stashed changes do not conflict with what you pulled or edited, it will just work, if not you get some merge conflicts that you can resolve like when you do a merge or rebase.

0
Sajib Khan On
$ git stash list            # see stash list(s) 
$ git stash apply           # default take the top one 'stash@{0}'
$ git stash pop             # pop = apply + drop, take the top stash changes then  delete it  

$ git stash apply stash@{1} # get back number 2 stash changes