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

From: Vincent Lefevre <[email-masked]>
Date: Wed, 6 May 2026 03:09:27 +0200

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 <[email-masked]> - 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)