Re: [BUG] "git diff --word-diff" gives a diff while they are only space changes
- From
Michael Montalbo <mmontalbo@gmail.com>
- Date
- May 28, 2026, 19:25 UTC
- Message-ID
- <CAC2QwmKjr2eiFNPPmERq7n-UjE-SF2vE4eHDanYE-4heWxzQVw@mail.gmail.com>
- In-Reply-To
- <CAC2QwmLXk=CXNo8+Ja0fL5pN1YYMTkh7XHAUwN1c9VxuFhyy4Q@mail.gmail.com>
On Wed, May 20, 2026 at 1:21 PM Michael Montalbo <mmontalbo@gmail.com> wrote:
Show 50 quoted lines
> > On Mon, May 18, 2026 at 8:11 PM Junio C Hamano <gitster@pobox.com> wrote: > > > > Chris Torek <chris.torek@gmail.com> writes: > > > > > 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 > > > > I understand your frustration in the second paragraph ;-) but let's > > not go there. The first paragraph is excellent. It gives readers a > > clear enough explanation to understand what is happening and stop > > complaining where there is nothing to complain about (which is > > already hinted by the "Note that" at the end). > > > > Thanks for the ideas, Chris. Here is my attempt at synthesizing Chris' > suggestions and Junio's feedback: > > The `--word-diff` option operates by taking the same line-by-line > diff that is produced without the option and computing > word-by-word changes within each hunk. This may produce a > larger diff than a dedicated word-diff tool would. If Git > acquires a different implementation in the future, the output > may change. Note that this is similar to the `--diff-algorithm` > option, which may also change the output. > > Does this work?
Updated the patch with the revised wording: https://lore.kernel.org/git/pull.2113.git.1778686956622.gitgitgadget@gmail.com/T/#t
Please feel free to pick up, modify, or drop as appropriate.