Undo git stash pop that results in merge conflict
I began making changes to my codebase, not realizing I was on an old topic branch. To transfer them, I wanted to stash them and then apply them to a new branch off of master. I used git stash pop to transfer work-in-progress changes to this new branch, forgetting that I hadn't pulled new changes into master before creating the new branch. This resulted in a bunch of merge conflicts and loss of a clean stash of my changes (since I used pop).
Once I recreate the new branch correctly, how I can I recover my stashed changes to apply them properly?
First step to undo git stash pop, unstage the merge conflicts using the following command:
$ git reset HEAD .
Then save the conflicted merge
$ git stash
Now return to master
$ git checkout master
In order to pull latest changes:
$ git fetch upstream; git merge upstream/master
In order to correct my new branch:
$ git checkout new-branch; git rebase master
In order to apply the correct stashed changes (now 2nd on the stack):
$ git stash apply stash@{1}