1

Here are two text files to compare:

1.txt:

one three four five 

2.txt:

one two three four 

Here are commands to create diff (for Windows):

git init copy 1.txt temp git add temp copy 2.txt temp git diff --minimal --word-diff del temp xrmdir /s /q ".git" 

Here is the output:

diff --git a/temp b/temp index 555f964..d993b66 100644 --- a/temp +++ b/temp @@ -1 +1 @@ one {+two+} three four[-five-] 

If we want to see original 1.txt by looking at diff, we'd see

one three fourfive 

(double space between one and three, no space between four and five).

Is there a way (command, I presume) to fix this, or is this normal? Am I missing something?

P.S.: git --version == 1.8.3.mysysgit.0

1 Answer 1

4

From the git-diff manpage:

plain

Show words as [-removed-] and {+added+}. Makes no attempts to escape the delimiters if they appear in the input, so the output may be ambiguous.

porcelain

Use a special line-based format intended for script consumption. Added/removed/unchanged runs are printed in the usual unified diff format, starting with a +/-/ character at the beginning of the line and extending to the end of the line. Newlines in the input are represented by a tilde ~ on a line of its own.

The result you get is working as expected. Makes no attempts to escape the delimiters if they appear in the input, so the output may be ambiguous.

So when I run git diff --minimal --word-diff=porcelain I get the response:

diff --git a/home/me/temp b/home/me/temp index 29338da..4d0e08d 100644 --- a/home/me/temp +++ b/home/me/temp @@ -1 +1 @@ one +two three four -five ~ 

which keeps the whitespace.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.