1diff-highlight 2============== 3 4Line oriented diffs are great for reviewing code, because for most 5hunks, you want to see the old and the new segments of code next to each 6other. Sometimes, though, when an old line and a new line are very 7similar, it's hard to immediately see the difference. 8 9You can use "--color-words" to highlight only the changed portions of 10lines. However, this can often be hard to read for code, as it loses 11the line structure, and you end up with oddly formatted bits. 12 13Instead, this script post-processes the line-oriented diff, finds pairs 14of lines, and highlights the differing segments. It's currently very 15simple and stupid about doing these tasks. In particular: 16 17 1. It will only highlight hunks in which the number of removed and 18 added lines is the same, and it will pair lines within the hunk by 19 position (so the first removed line is compared to the first added 20 line, and so forth). This is simple and tends to work well in 21 practice. More complex changes don't highlight well, so we tend to 22 exclude them due to the "same number of removed and added lines" 23 restriction. Or even if we do try to highlight them, they end up 24 not highlighting because of our "don't highlight if the whole line 25 would be highlighted" rule. 26 27 2. It will find the common prefix and suffix of two lines, and 28 consider everything in the middle to be "different". It could 29 instead do a real diff of the characters between the two lines and 30 find common subsequences. However, the point of the highlight is to 31 call attention to a certain area. Even if some small subset of the 32 highlighted area actually didn't change, that's OK. In practice it 33 ends up being more readable to just have a single blob on the line 34 showing the interesting bit. 35 36The goal of the script is therefore not to be exact about highlighting 37changes, but to call attention to areas of interest without being 38visually distracting. Non-diff lines and existing diff coloration is 39preserved; the intent is that the output should look exactly the same as 40the input, except for the occasional highlight. 41 42Use 43--- 44 45You can try out the diff-highlight program with: 46 47--------------------------------------------- 48git log -p --color | /path/to/diff-highlight 49--------------------------------------------- 50 51If you want to use it all the time, drop it in your $PATH and put the 52following in your git configuration: 53 54--------------------------------------------- 55[pager] 56 log = diff-highlight | less 57 show = diff-highlight | less 58 diff = diff-highlight | less 59---------------------------------------------