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

前端 未结 3 1208
栀梦
栀梦 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:44

    This slide from a perforce presentation is interesting:

    slide image

    The essential logic of a three-way merge tool is simple:

    • Compare base, source, and target files
    • Identify the "chunks" in the source and target files file:
      • Chunks that don't match the base
      • Chunks that do match the base
    • Then, put together a merged result consisting of:
      • The chunks that match one another in all 3 files
      • The chunks that don't match the base in either the source or in the target but not in both
      • The chunks that don't match the base but that do match each other (i.e., they've been changed the same way in both the source and the target)
      • Placeholders for the chunks that conflict, to be resolved by the user.

    Note that the "chunks" in this illustration are purely symbolic. Each could represent lines in a file, or nodes in a hierarchy, or even files in a directory. It all depends on what a particular merge tool is capable of.

    You may be asking what advantage a 3-way merge offers over a 2-way merge. Actually, there is no such thing as a two-way merge, only tools that diff two files and allow you to "merge" by picking chunks from one file or the other.
    Only a 3-way merge gives you the ability to know whether or not a chunk is a change from the origin and whether or not changes conflict.

提交回复
热议问题