[英]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. 我们最近在尝试合并两个分支时使用git遇到了一个非常奇怪的问题。 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 commits 分支A
是我们要合并回到具有其他一些提交的主干B
一些长期分支 B
in A
and then A
back into B
我们想将B
合并到A
,然后A
合并回B
git checkout A; git merge B
当执行git checkout A; git merge 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 checkout A; git merge B
我们遇到与A
引入的更改无关的合并冲突:那些位于A
认为未触及但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. 使用git annotate
和git log
跟踪冲突文件之一的祖先,我们有效地注意到冲突的位置具有共同的提交祖先1234
:A行在A
中用1234
注释,在B
中用5678
注释,但是git annotate file1 5678^
显示1234
对于冲突线。 I do not understand how this is possible and could not find any clue on a similar issue anywhere. 我不知道这是怎么可能的,并且在任何地方都找不到类似问题的任何线索。
The conflict file should be changed on branch A
after the common ancestry with branch B
. 与分支B
共同祖先后,应在分支A
上更改冲突文件。 And you can double check by git annotate
and git log
again. 您可以通过git annotate
和git log
再次检查。
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). 注意: git annotate
中的提交列表从旧的(在顶部)到新的(在底部)排序。
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
; 这意味着,在提交祖先commit common
,冲突文件在提交A3
和分支A
提交A4
中被更改; in branch B
, the conflict file was changes in commit B4
after that. 在分支B
,冲突文件是此后commit B4
中的更改。
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
| |
… …
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.