Git使用的差异版本是什么?diff2还是diff3?

5
有人知道git使用的是哪个diff版本吗?
例如,这篇文章详细解释了普通人可理解的diff算法,但实际使用的算法是什么呢?
对于一般知识,这里有diff2diff3的规格说明。
我知道你可以配置git使用diff2diff3
git config --global merge.conflictstyle diff3
2个回答

5
您似乎混淆了三件不同的事情:
  1. GNU diffutils提供的Unix命令行工具diff3
  2. Git提供的差异输出格式(其中diff3是非默认选项)
  3. Git用于生成差异的算法
Git支持4种不同的差异算法。
您可以通过命令行指定给git diff
  --minimal
       Spend extra time to make sure the smallest possible diff is produced.

   --patience
       Generate a diff using the "patience diff" algorithm.

   --histogram
       Generate a diff using the "histogram diff" algorithm.

   --diff-algorithm={patience|minimal|histogram|myers}
       Choose a diff algorithm. The variants are as follows:
   default, myers
       The basic greedy diff algorithm. Currently, this is the default.

   minimal
       Spend extra time to make sure the smallest possible diff is produced.

   patience
       Use "patience diff" algorithm when generating patches.

   histogram
       This algorithm extends the patience algorithm to "support low-occurrence common elements".

或通过 git 配置。
  diff.algorithm
   Choose a diff algorithm. The variants are as follows:

   default, myers
       The basic greedy diff algorithm. Currently, this is the default.

   minimal
       Spend extra time to make sure the smallest possible diff is produced.

   patience
       Use "patience diff" algorithm when generating patches.

   histogram
       This algorithm extends the patience algorithm to "support low-occurrence common elements".

你原始问题中的 diff2 pdf链接是关于 myers 算法的描述,似乎与 git 在 merge.conflictStyle 中称为 diff2 的双向冲突标记无关。
同样,unix 工具 diff3 与 git 称为 diff3 的三向冲突标记无关。

安德鲁,你在 HPE 工作吗?我也在那里工作。 - CodeWizard
我如何生成类似于Git合并冲突时提供的输出?GNU工具或其他地方是否有这样的工具? - dawid

0

我在配置文档中找到了答案:
git默认是diff2

merge.conflictStyle

指定合并时冲突块写入工作树文件的样式。

默认值为“merge”,它显示一个<<<<<<<冲突标记,
一方所做的更改,一个=======标记,
另一方所做的更改,
然后是一个>>>>>>>标记。另一种样式“diff3”添加了一个|||||||标记和=======标记之前的原始文本。


1
不,尽管它是diff3的替代选择,但它被称为“合并(merge)”,而不是“diff2”。 - Edward Thomson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接