insitu
insitu

Reputation: 4698

How can I have merge conflicts between 2 branches with common ancestor?

We have recently encountered a really odd issue using git while trying to merge two branches. The situation boils down to the following:

  1. branch A is some long-lived branch we want to merge back to main trunk B which has some other commits
  2. We want to merge B in A and then A back into B
  3. When doing git checkout A; git merge B we encounter merge conflicts which are unrelated to the changes introduced by A: Those are located into a bunch of files that are supposedly untouched by A but changed in B
  4. Using git annotate and git log to trace the ancestry of one of the conflicting file we effectively notice that the conflicting locations have a common commit ancestry 1234: One line is annotated with 1234 in A and 5678 in B but git annotate file1 5678^ shows 1234 for the conflicting line.

I do not understand how this is possible and could not find any clue on a similar issue anywhere.

Upvotes: 5

Views: 178

Answers (1)

Marina Liu
Marina Liu

Reputation: 38116

The conflict file should be changed on branch A after the common ancestry with branch B. And you can double check by git annotate and git log again.

1. List the commits which modified the conflict file in branch A and branch B separately:

git annotate filename A
git annotate filename B

Note: the commits list in git annotate are ordered from old (on the top) to new (in the bottom).

Assume the output of the commands as below:

$ git annotate filename A
commit A1
commit A2
commit common
commit A3
commit A4

$ git annotate filename B
commit B1
commit B2
commit B3
commit common
commit B4

That means, after the commit ancestry commit common, the conflict file was changed in commit A3 and commit A4 in branch A; in branch B, the conflict file was changes in commit B4 after that.

2. Show the git log as graph for the commits which changed the conflict file in all branches

And you can show the commits which changed the conflict file by graph with the command:

git log --oneline --decorate --graph --all -- filename

Then the graph will look like as below:

* commit A4 (branch A)
* commit A3
|   * commit B4 (branch B)
*   | commit Common
|  \
*   | commit A2
*   | commit A1
|   * commit B3
|   * commit B2
|   * commit B1
|   |
…   …

Upvotes: 1

Related Questions