4

Does anyone know which diff version is used by git?

This article for example explains in detail the diff algorithm for dummies but what is the actual algorithm which is used?

For general knowledge here are the specs for diff2 and diff3.

I know you can configure git to use diff2 or diff3

git config --global merge.conflictstyle diff3
wjandrea
  • 28,235
  • 9
  • 60
  • 81
CodeWizard
  • 128,036
  • 21
  • 144
  • 167

2 Answers2

5

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.

Andrew C
  • 13,845
  • 6
  • 50
  • 57
0

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.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167