What is the diff version git use? diff2 or diff3?

不想你离开。 提交于 2019-11-28 01:40:42

问题


Does anyone has clue which is the diff version used by git?

This article for example explain in details the diff algorithm for dummies but whats is the actual algorithm which is used?

For general knowledge here specs for diff2 & diff3.

  • diff2: http://www.xmailserver.org/diff2.pdf
  • diff3: http://www.cis.upenn.edu/~bcpierce/papers/diff3-short.pdf

I know you can configure git to use diff2 or diff3

git config --global merge.conflictstyle diff3

回答1:


You seem to be confusing 3 different things

  1. The unix command line tool diff3 provided by GNU diffutils
  2. The output format of the diff that git provides (in which diff3 is a non-default option)
  3. The algorithm that git uses to generate the diff

Git supports 4 different diff algorithms.

You can specify via the command line to 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".

or via git configuration.

  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".

The diff2 pdf-link in your original question is a description of the myers algorithm, and seems to be unrelated to the 2-way conflict markers git calls diff2 in merge.conflictStyle.

Similarly, the unix tool diff3 is unrelated to the 3-way conflict markers git calls diff3.




回答2:


I found the answer in the config documentation:
git defaults is diff2

merge.conflictStyle

Specify the style in which conflicted hunks are written out to working tree files upon merge.

The default is "merge", which shows a <<<<<<< conflict marker,
changes made by one side, a ======= marker,
changes made by the other side,
and then a >>>>>>> marker. An alternate style,

"diff3", adds a ||||||| marker and the original text before the ======= marker.



来源:https://stackoverflow.com/questions/34434750/what-is-the-diff-version-git-use-diff2-or-diff3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!