git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[BUG] "git diff --word-diff" gives a diff while they are only space changes

From
VLVincent Lefevre <vincent@vinc17.net>
Date
May 6, 2026, 01:09 UTC
Message-ID
<20260506010927.GE5260@qaa.vinc17.org>
Consider the following two 5-line files:
file1:
1
2
3
 2
4
file2:
1
 2
 3
 2
 4
On these files, "git diff --word-diff file1 file2" gives
--- a/file1
+++ b/file2
@@ -1,5 +1,5 @@
1
[-2-]
[-3-]
 2
 {+3+}
{+ 2+}
 4

instead of

--- a/file1
+++ b/file2
@@ -1,5 +1,5 @@
1
 2
 3
 2
 4

(e.g. as output by GNU wdiff 1.2.2).

Equivalently, the following command can be used under bash or zsh:

  git diff --word-diff <(printf "1\n2\n3\n 2\n4\n") \
                       <(printf "1\n 2\n 3\n 2\n 4\n")

Tested with git 2.39.5 (Debian 12), 2.53.0 (Debian unstable) and
2.54.0 (Termux/Android).

Issue initially found with

  git show --word-diff 1bf0b214deff2d0ccdcef3b2a4723369e014de3d

and more precisely

  git show --word-diff 1bf0b214deff2d0ccdcef3b2a4723369e014de3d attach.c

in the Mutt Git repository.
-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)
Next: Johannes Sixt
Message 1 of 5 in “[BUG] "git diff --word-diff" gives a diff while they are only space changes”
  1. Vincent LefevreMay 6, 2026
  2. Johannes SixtMay 8, 2026
  3. Vincent LefevreMay 8, 2026
  4. Johannes SixtMay 9, 2026
  5. Vincent LefevreMay 9, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.