Why is a 3-way merge advantageous over a 2-way merge?

前端 未结 3 1212
栀梦
栀梦 2020-11-22 15:41

Wikipedia says a 3-way merge is less error-prone than a 2-way merge, and often times doesn\'t need user intervention. Why is this the case?

An example where a 3-way

3条回答
  •  花落未央
    2020-11-22 16:39

    A three way merge where two changesets to one base file are merged as they are applied, as opposed to applying one, then merging the result with the other.

    For example, having two changes where a line is added in the same place could be interpreded as two additions, not a change of one line.

    For example

    file a has been modified by two people, one adding moose, one adding mouse.

    #File a
        dog
        cat
    
    #diff b, a
        dog
    +++ mouse
        cat
    
    #diff c, a
        dog
    +++ moose
        cat
    

    Now, if we merge the changesets as we apply them, we will get (3-way merge)

    #diff b and c, a
        dog
    +++ mouse
    +++ moose
        cat
    

    But if we apply b, then look at the change from b to c it will look like we are just changing a 'u' to an 'o' (2-way merge)

        #diff b, c
        dog
    --- mouse
    +++ moose
        cat
    

提交回复
热议问题