Consider a simple file like this:
Commited:
foo;
Edited:
bar;
Now, when I run git diff --word-diff-regex="[a-z]+"
, it gives me
[-foo-]{+bar+};
So, it shows that the word foo
has been replaced by bar
. Note that the semicolon is not marked as changed. That's fine.
Now, if I add another line to the file like this:
bar;
qux;
the above does not work anymore:
$ git diff --word-diff-regex="[a-z]+"
Expected output:
[-foo-]{+bar+};
{+qux;+}
Actual output:
[-foo-]{+bar;+}
{+qux+};
Note that the semicolon in the first line is now considered part of a word. The docs state
Anything between these matches is considered whitespace and ignored(!) for the purposes of finding differences.
Then why does it not ignore the semicolons? Is that a bug? Can I use a better regex to make it work?
I actually use a more sophisticated regex in reality, but the problem is the same.
Edit
Strangely, it works when the committed file contains an additional newline like so:
foo;