user1589188
user1589188

Reputation: 5736

gitlab highlighting whole line instead of just the characters changed in a long string

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'

Upvotes: 1

Views: 1194

Answers (1)

Martin Nyolt
Martin Nyolt

Reputation: 4650

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.

Upvotes: 3

Related Questions