3

I am taking the following example to ask a merge conflict question that I encountered at work.

Suppose I have a file named mainFile.txt in the master branch, and its content is:

 1 this is the first line in master branch 2 this is the second line in master branch 3 this is the third line in master branch 

From the master branch, I created two branches: branchA and branchB, each has new lines (from line 4 in both branches) added to the same mainFile.txt file:

The content of the mainFile.txt in branchA:

 1 this is the first line in master branch 2 this is the second line in master branch 3 this is the third line in master branch 4 This is the fourth line in branchA 5 this is the fifth line in branchA 

The content of the mainFile.txt in branchB:

 1 this is the first line in master branch 2 this is the second line in master branch 3 this is the third line in master branch 4 This is the fourth line in branchB 5 This is the fifth line in branchB 6 This is the sixth line in branchB 

Now, I need to merge both branches back to master. There is no problem when I merge branchA first to master. However, merge conflicts show up when I merge the branchB to master. From the following attached screenshot for the merge conflicts, I need to keep all the lines from both branchA and branchB. I was wondering how I should resolve the merge conflicts. I have been trying to use vimdiff, but it seems to me that I need to make a decision of keeping either branch (not both).

Thanks for help! enter image description here

2 Answers 2

3

It is better to use any 3-way merge tool like meld http://meldmerge.org/ which also takes in account the common ancestor for both these branches which means it is easier for you to identify the changes and work through merge. Using vi or text editor to merge large and conflicting code snippet becomes difficult since you cannot see the comparison in the same screen without scrolling down. You can select to retain both branches when you launch the merge using git mergetool when you have conflicts

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

1 Comment

Yes, for this you absolutely need a proper 3-way merge program. I use KDiff3 and I am very happy with it.
1

First you can merge branchA to the master. After that as you will try to merge the branchB to master from command line you will see the error something like

Automatic merge failed; fix conflicts and then commit the result

Now open your mainFile.txt of branchB. You will get one line present with your code

<<<<<<< HEAD

Because of the code below this line your branch has conflict. Do changes in your code manually according to your final requirements.

After that add, commit and push your mainFile.txt. You should be able to get your conflicts resolved after this.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.