简体   繁体   English

如何在具有共同祖先的2个分支之间合并冲突?

[英]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: 情况归结为以下几点:

  1. branch A is some long-lived branch we want to merge back to main trunk B which has some other commits 分支A是我们要合并回到具有其他一些提交的主干B一些长期分支
  2. We want to merge B in A and then A back into B 我们想将B合并到A ,然后A合并回B
  3. When doing 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更改的文件中
  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. 使用git annotategit 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 annotategit log再次检查。

1. List the commits which modified the conflict file in branch A and branch B separately: 1.在分支A和分支B中分别列出修改冲突文件的提交:

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中的更改。

2. Show the git log as graph for the commits which changed the conflict file in all branches 2.将git日志显示为所有更改分支中冲突文件的提交的图形

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM