git合并冲突如何发生? [英] how does exactly a git merge conflict happen?

查看:204
本文介绍了git合并冲突如何发生?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个git存储库并为其添加了一个文本文件。这是100%的学习目的。


  1. 我在文本文件中添加了1并将其提交给主文件。

  2. 从master创建了一个新的分支并附加了2。最后,从master创建了一个分支,并添加了3。


您可以解释一下这种情况或其他任何情况下可能发生的冲突吗? b $ b

解决方案

如果合并,您将会遇到冲突: > branch2 master (无冲突)

  • branch3 master (冲突):


    那是因为:


    • 共同的祖先是 master line empty)

    • 源内容为 branch3 (第二行包括3)
    • 目标内容位于 master 的最后一行(第二行包含2,来自 branch2 to master



    Git会要求您选择哪些内容保留(3,2或两者)。



    首先,在之后进行合并:

      git config merge.conflictstyle diff3 

    code>

    请参阅修复Git中的合并冲突?


    I have made a git repository and added a text file to it. This is 100% for learning purpose.

    1. I added "1" to the text file and committed it to master.

    2. Created a new branch from master and appended "2".

    3. Finally, created a branch from master and appended "3".

    Could you please explain how a conflict may occur in this, or any other, scenario?

    解决方案

    You will have a conflict if you merge:

    • branch2 to master (no conflict)
    • branch3 to master (conflict):

    That is because:

    • The common ancestor would be master (with a second line empty)
    • the source content is branch3 (with a second line including "3")
    • the destination content is on latest of master (with a second line including "2", from the merge of branch2 to master)

    Git will ask you to choose which content to keep ("3", "2", or both).

    First, do the merges after:

    git config merge.conflictstyle diff3
    

    See "Fix merge conflicts in Git?".

    这篇关于git合并冲突如何发生?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆