All of lore.kernel.org
 help / color / mirror / Atom feed
* [BUG] "git diff --word-diff" gives a diff while they are only space changes
@ 2026-05-06  1:09 Vincent Lefevre
  2026-05-08 12:48 ` Johannes Sixt
  0 siblings, 1 reply; 11+ messages in thread
From: Vincent Lefevre @ 2026-05-06  1:09 UTC (permalink / raw)
  To: git

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)

^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [BUG] "git diff --word-diff" gives a diff while they are only space changes
@ 2026-05-12 20:56 Michael Montalbo
  2026-05-12 21:17 ` Vincent Lefevre
  2026-05-14  7:37 ` Junio C Hamano
  0 siblings, 2 replies; 11+ messages in thread
From: Michael Montalbo @ 2026-05-12 20:56 UTC (permalink / raw)
  To: vincent; +Cc: git, j6t

On Sat, 9 May 2026 17:55:26 +0200, Vincent Lefevre wrote:
> For wdiff, it is just described as "display word differences between
> text files", and it does exactly that. For instance, if there are no
> differences in words, it shows no differences.
>
> For git with the --word-diff, there is actually no documentation,
> except the use of "changed words" and "word diff". No mention of
> line diff at all! So this is quite confusing.

Maybe something like this would be worth adding to the docs:

-- >8 --
diff --git a/Documentation/diff-options.adoc b/Documentation/diff-options.adoc
index 8a63b5e164..665473e61a 100644
--- a/Documentation/diff-options.adoc
+++ b/Documentation/diff-options.adoc
@@ -457,6 +457,11 @@ endif::git-diff[]
 +
 Note that despite the name of the first mode, color is used to
 highlight the changed parts in all modes if enabled.
++
+Word diff works by finding word-level changes within each hunk of
+the line-level diff.  The line-level alignment determines which
+changed lines are compared to each other, which can affect the
+word-level output.

 `--word-diff-regex=<regex>`::
        Use _<regex>_ to decide what a word is, instead of considering
-- >8 --

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-05-15 13:23 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-06  1:09 [BUG] "git diff --word-diff" gives a diff while they are only space changes Vincent Lefevre
2026-05-08 12:48 ` Johannes Sixt
2026-05-08 21:39   ` Vincent Lefevre
2026-05-09  6:16     ` Johannes Sixt
2026-05-09 15:55       ` Vincent Lefevre
  -- strict thread matches above, loose matches on Subject: below --
2026-05-12 20:56 Michael Montalbo
2026-05-12 21:17 ` Vincent Lefevre
2026-05-13 15:52   ` Michael Montalbo
2026-05-14  7:37 ` Junio C Hamano
2026-05-14  9:55   ` Vincent Lefevre
2026-05-15 13:22     ` Phillip Wood

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.