git diff
has this feature --color-moved=dimmed-zebra
which sounds really nifty but I just don't get it. If found zebra
to be very useful since it shows moved blocks. But dimmed_zebra
seems completely arbitrary to me. Why are "the bordering lines of two adjacent blocks...considered interesting"? How does this feature help me analyze the diff more effectively? I feel like this feature would be useful if I understood its intended purpose. A concrete example might be helpful.
Here's the snippet from the manpage.
zebra
Blocks of moved text of at least 20 alphanumeric characters are detected greedily. The detected blocks are painted using either the color.diff.{old,new}Moved color or color.diff.{old,new}MovedAlternative. The change between the two colors indicates that a new block was detected.
dimmed-zebra
Similar to zebra, but additional dimming of uninteresting parts of moved code is performed. The bordering lines of two adjacent blocks are considered interesting, the rest is uninteresting.
The dimmed-zebra
mode is useful when the patch consists mostly of moved or copied code with a few lines changed in the middle of the copied code. Take, for example, a particular commit from Git (this link won't show the mode, however).
The zebra
mode shows that there are two separate moved blocks: the former and the latter, colored in purple and blue, both of which are moved later with a single line inserted between them. Here's an example of one moved stanza:
It's a little hard to notice the added line; it doesn't really stand out.
With dimmed-zebra
, almost all of the moved code is grey because it's ultimately uninteresting. The only things that are highlighted in colors are the end of the first block, the beginning of the second block (the next line), and the lines that's added in the destination. This mode lets you focus on (a) the added line and (b) the borders of where they came from, without caring about any of the moved code.
Here's what that code looks like in dimmed-zebra
mode. Notice how your eye is drawn to the relevant portions only:
So basically, this is just an optimization for human vision to make it easier to notice what really matters.
@bk2204's answer helped me understand with a nice example and now I want to offer another answer.
What does it mean for moved lines to be "interesting", and not dimmed?
When you see two highlighted lines that are at the border of two removed and moved blocks of code, you should think, "These lines are not adjacent anymore; Some code was inserted here or these blocks were completely separated."
Likewise, when you see two highlighted lines that are at the border of two added and moved blocks of code, you should think, "These lines did not used to be adjacent; Some code was removed here or these blocks came from completely different places".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With