耐心算法与默认的 git diff
算法有何不同,我什么时候想使用它?
最佳答案
您可以阅读 a post from Bram Cohen ,耐心差异算法的作者,但我发现了this blog post很好地总结了 patience diff 算法:
Patience Diff, instead, focuses its energy on the low-frequency high-content lines which serve as markers or signatures of important content in the text. It is still an LCS-based diff at its core, but with an important difference, as it only considers the longest common subsequence of the signature lines:
Find all lines which occur exactly once on both sides, then do longest common subsequence on those lines, matching them up.
什么时候应该使用 patience diff?根据 Bram 的说法,patience diff 对这种情况有好处:
The really bad cases are ones where two versions have diverged dramatically and the developer isn't being careful to keep patch sizes under control. Under those circumstances a diff algorithm can occasionally become 'misaligned' in that it matches long sections of curly brackets together, but it winds up correlating the curly brackets of functions in one version with the curly brackets of the next later function in the other version. This situation is very ugly, and can result in a totally unusable conflict file in the situation where you need such things to be presented coherently the most.
关于git - `git diff --patience` 是做什么用的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4045017/