The "patience" algorithm throws out lines that repeat, before matching up the remaining lines. (This is a little oversimplified—it throws out repeated lines in the sub-box it's differencing; on each recursion, it throws out whichever lines repeat within the sub-box only, rather than across the entire file. For the first pass, though, the sub-box is "the entire file".)
In your example, there are two lines that repeat, namely margin: 0;
and }
. So the initial input to the patience diff subsequence-finder is:
.foo1 {
.bar {
for the left or "A" side and:
.bar {
.foo1 {
color: green;
for the right or "B" side.
The blank line matches, and the .foo1 {
line matches. But these are not in order, and are only one element long anyway, so they are not useful.
The algorithm as a whole then falls back to normal diff, and you get the same output as for normal diff.
Edit: how to construct examples
It's not that easy to construct inputs for which the algorithm gives different results. What you need is to have long common subsequences that are found after discarding repeated lines, but not found without doing so. Consider writing something like:
line 1
line 2
noise
noise
noise
noise
line 3
noise
noise
noise
line 4
as part of the input (on one or both "sides", A and B, of the diff), and then making changes only in "non-noise" lines. Plain git diff
will synchronize on the noise
lines (use a different number of noise
lines in each section), while patience diff will throw them away. If one of the many noise lines sections makes up part of the longest common subsequence, plain diff will choose to match that up, and then recurse to find differences within the sections above or below the match. When the de-noised version has a different longest common subsequence, patience diff will match those up, and recurse on the (now-different) unmatched sub-sequences.