git版本的差异版本是什么?diff2或diff3?

Cod*_*ard 3 git diff git-diff

有人知道git使用的diff版本是什么吗?

例如,本文详细解释了虚拟变量的diff算法,但是实际使用的算法是什么?

有关常识,请参见diff2&的规范diff3

我知道您可以配置git使用diff2diff3

git config --global merge.conflictstyle diff3
Run Code Online (Sandbox Code Playgroud)

And*_*w C 5

您似乎混淆了三件事

  1. GNU diffutilsdiff3提供的unix命令行工具
  2. git提供的差异的输出格式(这diff3是非默认选项)
  3. git用于生成差异的算法

Git支持4种不同的diff算法。

您可以通过命令行指定 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".
Run Code Online (Sandbox Code Playgroud)

或通过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".
Run Code Online (Sandbox Code Playgroud)

diff2您原始问题中的pdf链接是对该myers算法的描述,似乎与git调用diff2中的2向冲突标记无关merge.conflictStyle

同样,unix工具diff3与git调用3向冲突标记无关diff3


Cod*_*ard 0

我在配置文档中找到了答案:
git defaults is diff2

merge.conflictStyle

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

默认值为“merge”,它显示 <<<<<<< 冲突标记、
一侧所做的更改、 ======= 标记、
另一侧所做的更改,
然后是 >>>> >>> 标记。另一种风格,

“diff3”,添加 ||||||| 标记和 ======= 标记之前的原始文本。