【问题标题】:Git merge conflict: different branch edits different linesGit合并冲突:不同的分支编辑不同的行
【发布时间】:2016-11-09 06:43:11
【问题描述】:

我正在测试git merge的一些情况
我创建了一个 sample.txt,请参阅下面的后续操作

添加然后提交到主分支
sample.txt 包含

aaa  
bbb

创建并签出到 branch1 并编辑 sample.txt---添加然后提交
branch1 sample.txt

aaa  
bbc  

签出到master并编辑sample.txt---添加然后提交
ma​​ster sample.txt

aad  
bbb  

运行git merge branch1我收到以下通知

Auto-merging sample  
CONFLICT (content): Merge conflict in sample  
Automatic merge failed; fix conflicts and then commit the result. 

sample.txt 包含

<<<<<<< HEAD  
aad  
bbb  
=======  
aaa  
bbc  
>>>>>>>> branch1  

master 在第 1 行进行了编辑
branch1 在第 2 行进行了编辑
如果我在 master 和 branch1 上编辑第 1 行,我会理解合并冲突

这种情况下的合并冲突是什么?
下面怎么有sample.txt的输出?

aad  
bbc

【问题讨论】:

  • 请不要无故添加语言标签。

标签: git


【解决方案1】:

合并冲突是在HEAD 你有

aad
bbb

而在Branch1 你有

aaa
bbc

如果您想要aadaaa 来解决此冲突,请在bbbbbc 之间进行选择。如果你想要 aadbbc 例如替换:

<<<<<<< HEAD  
aad  
bbb  
=======  
aaa  
bbc  
>>>>>>>> branch1 

aad
bbc

【讨论】:

    【解决方案2】:

    此外,你的 git 配置中的这个设置在处理合并冲突时会派上用场;这有助于了解被合并文件的共同基础。

    git config --global merge.conflictstyle diff3

    来源: 14 ways to resolve merge conflicts

    【讨论】:

      猜你喜欢
      • 2022-10-05
      • 2022-11-03
      • 2012-12-08
      • 2019-08-11
      • 1970-01-01
      • 2019-08-04
      • 1970-01-01
      • 1970-01-01
      • 2016-10-05
      相关资源
      最近更新 更多