What is `git diff –patience` for?

You can read a post from Bram Cohen, the author of the patience diff algorithm, but I found this blog post to summarize the patience diff algorithm very well:

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.

When should you use patience diff? According to Bram, patience diff is good for this situation:

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.

Leave a Comment