Reputation: 4698
We have recently encountered a really odd issue using git while trying to merge two branches. The situation boils down to the following:
A
is some long-lived branch we want to merge back to main trunk B
which has some other commitsB
in A
and then A
back into B
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
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
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.
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.
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