Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.4k points)

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?

1 Answer

0 votes
by (27.5k points)

First, 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}

Related questions

0 votes
1 answer
0 votes
1 answer
+4 votes
1 answer
0 votes
1 answer
asked Aug 2, 2019 in DevOps and Agile by Han Zhyang (19.7k points)

Browse Categories