1

Not sure if this is in general the git thing or gitlab, but I don't like it highlighted a rather long sub-section of a long continuous string in deeper colour including parts that were not changed when only some characters are changed in the string.

Is there a way to configure gitlab not to do this? i.e. just highlights those characters updated only

e.g. this is what I got on gitlab 8.10

enter image description here

and I expect it to hightlight only the '2' between 't' and 'i' and highlight the 'g' between 'm' and 'a'

user1589188
  • 5,316
  • 17
  • 67
  • 130

1 Answers1

3

This feature was introduced in Gitlab 8.10 (see section "Inline Diffs").

git itself uses line-based diffs, so it will internally always store the complete changed lines. However, git tools also allow to visually highlight only those changed parts, e.g. with git diff --word-diff=color.

Edit

What Gitlab 8.10 introduces are additional highlights in changed lines. I.e. the complete changed lines will be highlighted with a light green/red, and the actual changes within a line will be highlighted with a darker green/red. This is what you see in your figure:

word based diff 1

and in the figure of Gitlab's release notes:

word based diff 2 gitlab

Apparently, Gitlab highlights the largest part of the line that contains any changes. It does not try to produce minimal changes, probably due to performance reasons.

The git --word-diff=color option (including gitk's Markup words and Color words setting) do produce fewer highlights. Compare Gitlab's diff:

word based diff 3 gitlab

with the same diff from gitk:

word based diff 3 gitk

However, even --word-diff=color will—as the name suggests—only highlight on a word-by-word basis. For your example, it will simply highlight both words. Here is your case reproduced in gitk with Color words:

word based diff 1 gitk

For the command line tools (e.g. git diff), there is actually an option --color-words=. that will do what you want:

char based diff 1

However, neither gitk nor Gitlab know this option, as far as I know.

Community
  • 1
  • 1
Martin Nyolt
  • 4,463
  • 3
  • 28
  • 36
  • Sorry I had to unpick yours as the answer because I was just on 8.10 and still it is not highlighting only those changed, unless there is an option or config to turn that on that I dont know. – user1589188 Aug 24 '16 at 00:40