0

Let's assume I want to merge branch_B to branch_A. I did:

git checkout branch_A
git merge branch_B

This resulted into a wall of conflicts that took me quite a long time to fix. Then, I had to do something urgently on branch_C. I did:

git stash
git checkout branch_C

Now, I am done with the branch_C and want to continue with my merge. I did:

git checkout branch_A
git stash pop

However, the merge is now viewed as a simple diff between branch_A and my merge attempt. How do I unstash these changes as a merge being in progress?

ivaigult
  • 6,198
  • 5
  • 38
  • 66
  • There is a relevant question [here](https://stackoverflow.com/questions/34685407/can-i-git-stash-a-merge-in-progress). Clearly, a merge in progress can be stashed. But it doesn't say if I can resume merging. – ivaigult Jan 08 '21 at 20:48
  • Try merging again? If you can’t, as in you’re still merging, apply the stashed changes and run `git merge --continue` – evolutionxbox Jan 08 '21 at 20:49
  • An in-progress merge literally *can't* be stashed until all conflicts are resolved. Once they are resolved, `git stash` saves the resolutions, but destroys the in-progress merge; it probably should refuse to do the stash action. (I'd argue the fact that it lets you do this is a bit of a bug in Git.) A better plan for urgent side work is to use `git worktree add`. Of course it's too late for that here; but see jthill's answer below. – torek Jan 09 '21 at 04:05

1 Answers1

4

You can simply restart it and reload the stash results

git merge branch_B
git read-tree --reset -u stash

if you had work tree changes that weren't added, i.e. the stashed index state didn't match the stashed work tree, follow up with git read-tree stash^2 to reload the index.

jthill
  • 55,082
  • 5
  • 77
  • 137