'Why is a space missing in the result of git diff --color-words?
result of git diff =>
diff --git a/test.txt b/test.txt
index 064858a..31140d8 100644
--- a/test.txt
+++ b/test.txt
@@ -1 +1 @@
-There is a problem.
+There is problem.
result of git diff --color-words =>
diff --git a/test.txt b/test.txt
index 064858a..31140d8 100644
--- a/test.txt
+++ b/test.txt
@@ -1 +1 @@
There isa problem.
Why is it "There isa problem." and not "There is a problem."? A space is missing.
Solution 1:[1]
That's the expected behavior of git word-diff in any shell. If you remove a word in the middle of a line, it will not show the leading whitespace. You could have any number of spaces between is and problem in your original text, and the output would be the same.
git diff --color-words is the same as git word-diff=color.
Without specifying a custom regex, word-diff is only capable of showing you differences in runs of non-whitespace characters. As per the docs, the "output may be ambiguous" when there are changes made to the whitespace.
To get a better understanding of how this output works, try running it as git word-diff=plain.
If you look at this readme for the library gitwdiff, you can see a comparison between the outputs of a standard git word-diff and their version gitwdiff. It clearly shows that removed words in word-diff do not render the whitespace change.
wdiff is a more specialized command-line utility for diffing words, and it shows the output with the expected whitespace, so you may prefer that.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | TonyArra |
