4

I've have some luck with the following command:

git diff --color-words='[^][<>()\{},.;:?/|\\=+*&^%$#@!~`"'\''[:space:]]+|[][<>(){},.;:?/|\\=+*&^%$#@!~`"'\'']'

but it doesn't seem to negate the square brackets properly in the first character class.

I've tried this:

git diff --color-words='[^\]\[<>()\{},.;:?/|\\=+*&^%#@!~`"'\''[:space:]]+|[\]\[<>(){},.;:?/|\\=+*&^%#@!~`"'\'']'

in order to make the square brackets literal, but it fails with the message fatal: Invalid regular expression.

Edit:

The output I get is like so:

foobarfo]ob[ar

But what I'm after is:

fo]oob[ar

Walf
  • 8,535
  • 2
  • 44
  • 59

2 Answers2

2

With word diff you will always see the word you removed next to the new one.

This is why you have the word before your new change.

Read this question, very detailed answer:

Filtering a diff with a regular expression

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • I understand that, but the purpose of that regex is to define what a single word is made of. In this case, it should be a run of non-space and non-punctuation characters, or a single punctuation character. – Walf Mar 24 '16 at 14:38
  • You were right. It was detecting a word that was 'broken' by the change. The regex works as expected when the punctuation change is outside of a word. – Walf Mar 25 '16 at 13:19
2

Even though I didn't need it in the end, to see character-level differences like my example, this works:

git diff --color-words=.
Walf
  • 8,535
  • 2
  • 44
  • 59