3

tl;dr

I have done a master -> feature merge to update and resolve conflicts before the actual merge.
Can I rebase feature onto master instead and apply the conflict resolution from the merge?

What I have:
 o - TODO merge feature -> master |\ | o feature - "Merge remote-tracking branch 'origin/master' into feature" |/| o | master | o - "Implement some new feature here" | | ... |/ o 
What I want:
 o - TODO merge feature -> master |\ | o feature - "Implement some new feature here" |/ o master | ... | o 

Long version

I want to merge a feature branch that is quite old and has conflicts, because other work was merged to master in the mean time. First I updated the feature branch from master by a master -> feature merge. Now I am able to successfully merge the feature branch back without conflicts. But looking at he history now, I realised I should have rebased my feature onto the latest master instead. Unfortunatelly I had to resolve quite an amount of conflicts, can I reuse the current state?

1
  • No, I don't think you can reuse the current state. While similar conflicts would probably occur in the course of a rebase, they would happen at different points, as each of your commits is reapplied. So, I vote for just redoing things using a rebase. Commented Mar 5, 2018 at 10:57

1 Answer 1

1

As Tim Biegeleisen commented, you can't reuse the merge commit (which is where you resolved your conflicts) in a rebase directly.

The merge conflicts are resolved in a the merge commit, which will drop off when you do the rebase master command.

However, if there merge conflicts were especially painful and/or if you only have a few commits that you're working with, you could follow a workflow of:

  • merge master into feature
  • resolve conflicts
  • do a soft reset of your feature branch
  • stash the changes
  • rebase master
  • replay your stash
  • recreate your commits

By doing the soft reset, the actual file changes after the merge are preserved so you won't need to resolve the conflicts the way you'd need to do if you were just rebasing.

Sign up to request clarification or add additional context in comments.

3 Comments

This looks promising. I only have one commit, but it contains lots of changes. I could do a soft reset, then revert the work - this should yield the conflict resolution alone right? I will play with it a bit.
It wont yield the conflict resolution alone, it'll contain the original work and the conflict resolution - which sounds like exactly what you what especially since there's only one commit.
And I realized I didn't fully explain the steps - the trick is once you've done your soft reset, then you can stash the changes and then get your feature branch up to date with master (ie rebase), re-apply the stash and then you'll have all of your working changes, at which point you can then recreate your commits and you should be good to go

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.