{"thread":{"id":"65599","subject":"[BUG] \"git diff --word-diff\" gives a diff while they are only space changes","startedAt":"2026-05-06T01:12:00Z","lastAt":"2026-05-09T15:55:30Z","messageCount":5,"participants":["Vincent Lefevre","Johannes Sixt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"542797","messageId":"20260506010927.GE5260@qaa.vinc17.org","threadId":"65599","inReplyTo":null,"subject":"[BUG] \"git diff --word-diff\" gives a diff while they are only space changes","fromName":"Vincent Lefevre","fromEmail":"vincent@vinc17.net","sentAt":"2026-05-06T01:09:27Z","receivedAt":"2026-05-06T01:12:00Z","isPatch":false,"body":"Consider the following two 5-line files:\n\nfile1:\n\n1\n2\n3\n 2\n4\n\nfile2:\n\n1\n 2\n 3\n 2\n 4\n\nOn these files, \"git diff --word-diff file1 file2\" gives\n\n--- a/file1\n+++ b/file2\n@@ -1,5 +1,5 @@\n1\n[-2-]\n[-3-]\n 2\n {+3+}\n{+ 2+}\n 4\n\ninstead of\n\n--- a/file1\n+++ b/file2\n@@ -1,5 +1,5 @@\n1\n 2\n 3\n 2\n 4\n\n(e.g. as output by GNU wdiff 1.2.2).\n\nEquivalently, the following command can be used under bash or zsh:\n\n  git diff --word-diff <(printf \"1\\n2\\n3\\n 2\\n4\\n\") \\\n                       <(printf \"1\\n 2\\n 3\\n 2\\n 4\\n\")\n\nTested with git 2.39.5 (Debian 12), 2.53.0 (Debian unstable) and\n2.54.0 (Termux/Android).\n\nIssue initially found with\n\n  git show --word-diff 1bf0b214deff2d0ccdcef3b2a4723369e014de3d\n\nand more precisely\n\n  git show --word-diff 1bf0b214deff2d0ccdcef3b2a4723369e014de3d attach.c\n\nin the Mutt Git repository.\n\n-- \nVincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>\n100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>\nWork: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)\n"},{"id":"542907","messageId":"7cedf86c-5db7-45ef-b8d4-034b792f0def@kdbg.org","threadId":"65599","inReplyTo":"20260506010927.GE5260@qaa.vinc17.org","subject":"Re: [BUG] \"git diff --word-diff\" gives a diff while they are only space changes","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2026-05-08T12:48:01Z","receivedAt":"2026-05-08T12:48:10Z","isPatch":false,"body":"Am 06.05.26 um 03:09 schrieb Vincent Lefevre:\n> Consider the following two 5-line files:\n> \n> file1:\n> \n> 1\n> 2\n> 3\n>  2\n> 4\n> \n> file2:\n> \n> 1\n>  2\n>  3\n>  2\n>  4\n> \n> On these files, \"git diff --word-diff file1 file2\" gives\n> \n> --- a/file1\n> +++ b/file2\n> @@ -1,5 +1,5 @@\n> 1\n> [-2-]\n> [-3-]\n>  2\n>  {+3+}\n> {+ 2+}\n>  4\n> \n> instead of\n> \n> --- a/file1\n> +++ b/file2\n> @@ -1,5 +1,5 @@\n> 1\n>  2\n>  3\n>  2\n>  4\n> \n> (e.g. as output by GNU wdiff 1.2.2).\n\nThis is expected behavior.\n\ngit diff --word-diff is not agnostic to whitespace; if you drop\n--word-diff, you see the line-diff that the word-diff is based on. If\nyou want whitespace-agnostic word-diff, you have to add -w.\n\n-- Hannes\n\n"},{"id":"542932","messageId":"20260508213943.GP5260@qaa.vinc17.org","threadId":"65599","inReplyTo":"7cedf86c-5db7-45ef-b8d4-034b792f0def@kdbg.org","subject":"Re: [BUG] \"git diff --word-diff\" gives a diff while they are only space changes","fromName":"Vincent Lefevre","fromEmail":"vincent@vinc17.net","sentAt":"2026-05-08T21:39:43Z","receivedAt":"2026-05-08T21:39:51Z","isPatch":false,"body":"On 2026-05-08 14:48:01 +0200, Johannes Sixt wrote:\n> This is expected behavior.\n> \n> git diff --word-diff is not agnostic to whitespace; if you drop\n> --word-diff, you see the line-diff that the word-diff is based on. If\n> you want whitespace-agnostic word-diff, you have to add -w.\n\nThis is not how it is documented. Even when using \"git diff\" without\n--word-diff, but with GNU wdiff instead, the output is fine:\n\n$ git diff file1 file2 | wdiff -d\ndiff --git a/file1 b/file2\nindex da04344..0074613 100644\n[--- a/file1-]\n{+++ b/file2+}\n@@ -1,5 +1,5 @@\n1\n 2\n 3\n 2\n 4\n\n-- \nVincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>\n100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>\nWork: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)\n"},{"id":"542936","messageId":"cb359a26-2878-41a0-a554-9bcd28c7404c@kdbg.org","threadId":"65599","inReplyTo":"20260508213943.GP5260@qaa.vinc17.org","subject":"Re: [BUG] \"git diff --word-diff\" gives a diff while they are only space changes","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2026-05-09T06:16:48Z","receivedAt":"2026-05-09T06:16:58Z","isPatch":false,"body":"Am 08.05.26 um 23:39 schrieb Vincent Lefevre:\n> On 2026-05-08 14:48:01 +0200, Johannes Sixt wrote:\n>> This is expected behavior.\n>>\n>> git diff --word-diff is not agnostic to whitespace; if you drop\n>> --word-diff, you see the line-diff that the word-diff is based on. If\n>> you want whitespace-agnostic word-diff, you have to add -w.\n> \n> This is not how it is documented. Even when using \"git diff\" without\n> --word-diff, but with GNU wdiff instead, the output is fine:\n> \n> $ git diff file1 file2 | wdiff -d\n> diff --git a/file1 b/file2\n> index da04344..0074613 100644\n> [--- a/file1-]\n> {+++ b/file2+}\n> @@ -1,5 +1,5 @@\n> 1\n>  2\n>  3\n>  2\n>  4\n\nIt would have helped if you had pointed to, or cited, the documentation.\nI cannot find documentation from which I can derive that the above\n*must* be the correct output. In particular, I don't find any mention\nthat --word-diff operates exactly like GNU wdiff.\n\n-- Hannes\n\n"},{"id":"542948","messageId":"20260509155526.GQ5260@qaa.vinc17.org","threadId":"65599","inReplyTo":"cb359a26-2878-41a0-a554-9bcd28c7404c@kdbg.org","subject":"Re: [BUG] \"git diff --word-diff\" gives a diff while they are only space changes","fromName":"Vincent Lefevre","fromEmail":"vincent@vinc17.net","sentAt":"2026-05-09T15:55:26Z","receivedAt":"2026-05-09T15:55:30Z","isPatch":false,"body":"On 2026-05-09 08:16:48 +0200, Johannes Sixt wrote:\n> Am 08.05.26 um 23:39 schrieb Vincent Lefevre:\n> > On 2026-05-08 14:48:01 +0200, Johannes Sixt wrote:\n> >> This is expected behavior.\n> >>\n> >> git diff --word-diff is not agnostic to whitespace; if you drop\n> >> --word-diff, you see the line-diff that the word-diff is based on. If\n> >> you want whitespace-agnostic word-diff, you have to add -w.\n> > \n> > This is not how it is documented. Even when using \"git diff\" without\n> > --word-diff, but with GNU wdiff instead, the output is fine:\n> > \n> > $ git diff file1 file2 | wdiff -d\n> > diff --git a/file1 b/file2\n> > index da04344..0074613 100644\n> > [--- a/file1-]\n> > {+++ b/file2+}\n> > @@ -1,5 +1,5 @@\n> > 1\n> >  2\n> >  3\n> >  2\n> >  4\n> \n> It would have helped if you had pointed to, or cited, the documentation.\n> I cannot find documentation from which I can derive that the above\n> *must* be the correct output. In particular, I don't find any mention\n> that --word-diff operates exactly like GNU wdiff.\n\nFor wdiff, it is just described as \"display word differences between\ntext files\", and it does exactly that. For instance, if there are no\ndifferences in words, it shows no differences.\n\nFor git with the --word-diff, there is actually no documentation,\nexcept the use of \"changed words\" and \"word diff\". No mention of\nline diff at all! So this is quite confusing.\n\nNote: This isn't even a line-based diff with highlighted word diff\nas done by some tools, such as Emacs diff-mode.\n\n-- \nVincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>\n100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>\nWork: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)\n"}]}