Resolving merge conflict with several commits on a branch

58 Views Asked by At

I have a master branch, branch_a, branch_b branch_a I cut from master where I have local & origin commits as a1, a2, a3, a4 Now I cut branch_b where I have local & origin commits as b1, b2, b3, b4

now I merged branch_b with the master [squashed the commits from branch_b] hence my branch_a is conflicted (I am editing same files in both) when I try to resolve these conflict it start resolving them from the commit a1 while I want to resolve from a4 as the changes b/w a1,2,3,4 doesn't matter for me

Is squashing going to help?

I am thinking about squashing. But want to know official/better process?

edit: this doesn't intend to prevent conflicts it just means to reduce it.

2

There are 2 best solutions below

0
Mustafa Ertug Yaprak On

Switch to master.

git cherry-pick <id-of-commit-a4>

As a result, the changes from the commit are brought to the Staging Area. You need to resolve any conflicts and then commit them. Keep in mind cherry-picking isn't merging. You need the pick other commits that you want to apply to master, too.

2
Valerij Dobler On

First of all, try not to work by yourself on two branches and especially on the same lines. (Why would you want to do this to yourself?)

Merge conflicts arise when you have conflicting changes which were made on both branches participating in the merge. I reckon you are on par with that.

By merging a branch with multiple new commits you can have merge conflicts with every commit and you have to resolve them for every commit one at a time.

This is not necessarily a problem which just disappears if you squash the commits, but the merge conflicts get combined or might cancel out.

When you get to the point that you resolve a merge conflict, you are deciding on which piece of code should live on, on the branch on which you are merging your changes for every conflict. This is very dependent on the situation and that is why this can't be answered in general. Aren't there more senior peers whom you can consult?