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

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

From
Chris Torek <chris.torek@gmail.com>
Date
May 19, 2026, 02:31 UTC
Message-ID
<CAPx1Gvd_FqnsjCkpAA5uy7aDz9oQnWx7WTvKk-kLWemkqF9PsQ@mail.gmail.com>
In-Reply-To
<CAC2Qwm+BLNf-2kvePKNF-FKQX3raOBzSRmwd0ZEdzmo8TqkMGA@mail.gmail.com>
On Mon, May 18, 2026 at 7:11 PM Michael Montalbo <mmontalbo@gmail.com> wrote:
> Yeah, I was trying to explain the difference Vincent saw compared to wdiff,
> but I agree with your criticism. In "beating around the bush" regarding
> implementation details / making a direct comparison to wdiff, it has been
> hard to craft a meaningful message.
My opinion is: don't do that, just get right to it.
> > If we document the algorithm in such detail, we cast it in stone. I
> > wouldn't want to paint ourselves into that corner.
> I also agree with this sentiment. I haven't been able to come up with a
> message that threads the needle appropriately, so I'm open to dropping
> the patch or reworking it if others have suggestions.

Call it an "implementation note" (or, if you like, a "practical consideration"?). Something along these lines might work...

  Implementation Note
  The --word-diff option currently operates by taking the same
  line by line diff that you get without the option, then massaging
  the result into a word-by-word difference. This may cause an
  unnecessarily-larger diff than you would see with a more-clever
  implementation. If and when Git acquires a more-clever
  implementation, the output may change. Note that this is
  similar to the --diff-algorithm option, which may change the
  output.
  Regardless of which algorithm is used, _any_ diff simply shows
  _a_ way to achieve some particular change. It's impossible for
  any algorithm to tell whether someone deleted two lines and
  then put one back exactly as it appeared earlier, saving the
  resulting text, vs deleting a single line, for instance. Only a
  keystroke-by-keystroke logger would be able to tell what the
  human operator actually typed into some editor. Git does
  not have that information, and having it is not desired.
Chris
Previous: Michael MontalboNext: Junio C Hamano
Message 10 of 14 in “Re: [BUG] "git diff --word-diff" gives a diff while they are only space changes”
  1. Michael MontalboMay 12, 2026
  2. Vincent LefevreMay 12, 2026
  3. Michael MontalboMay 13, 2026
  4. Junio C HamanoMay 14, 2026
  5. Vincent LefevreMay 14, 2026
  6. Phillip WoodMay 15, 2026
  7. Michael MontalboMay 18, 2026
  8. Johannes SixtMay 18, 2026
  9. Michael MontalboMay 19, 2026
  10. Chris TorekMay 19, 2026
  11. Junio C HamanoMay 19, 2026
  12. Michael MontalboMay 20, 2026
  13. Michael MontalboMay 28, 2026
  14. Vincent LefevreJun 8, 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.