问题
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.pdfdiff3
: 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
- The unix command line tool
diff3
provided by GNU diffutils - The output format of the diff that git provides (in which
diff3
is a non-default option) - 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