Reading — step 1 of 5
Read
~1 min readProduction
Patience Diff
Myers diff sometimes produces "ugly" diffs for code:
Original:
function foo() {
return 1;
}
function bar() {
return 2;
}
Modified:
function bar() {
return 2;
}
function foo() {
return 1;
}
Myers might produce a confusing minimal-edit diff. Patience diff (Bram Cohen, 2009) produces clearer diffs by:
- Find LINES that appear EXACTLY ONCE in both files. These are "unique anchor" lines.
- Find the longest common subsequence of these anchor lines.
- The anchors split each file into chunks; recursively diff each chunk.
The result is more visually intuitive — large block reorders show as block moves.
git diff --patience enables it. --histogram is similar but faster.
For most code review tools (GitHub, Gerrit), the diff visualization matters more than minimality. Patience and histogram produce diffs people understand more easily.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…