how to get the stash back after pulling

59,569

Solution 1

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.

Solution 2

$ 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
Share:
59,569

Related videos on Youtube

farm command
Author by

farm command

Updated on October 04, 2020

Comments

  • farm command
    farm command over 3 years

    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.

  • farm command
    farm command over 7 years
    I used git stash pop but it didn't return all the changes just some of them, what could be the reason?
  • Vampire
    Vampire over 7 years
    Without any error message? Cannot be. Either it can apply all changes or it fails with some error message like merge conflict and didn't pop from the stash to not risk loosing changes. You can look at git stash list, maybe you stashed your changes in multiple steps? If there are stashes, you can diff them as usual like git diff stash^! to see what is in there.
  • Vampire
    Vampire over 7 years
    Or maybe the changes you did were exactly the same in what you got from remote and thus you don't see them as changes anymore as they are already committed.