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

Re: [PATCH] add -p: introduce 'w' command to view hunk with --word-diff

From
D. Ben Knoble <ben.knoble@gmail.com>
Date
May 7, 2026, 14:39 UTC
Message-ID
<CALnO6CCsOMyLxAhGW10L4duaahUORwedfmtdpY3zDGpQcZoP2Q@mail.gmail.com>
In-Reply-To
<e640ac2d-9e46-4f1e-9aef-deac80c65361@gmail.com>
On Thu, May 7, 2026 at 9:28 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 17 quoted lines
>
> Hi Javier
>
> On 07/05/2026 00:54, Javier Bassi wrote:
> > When using `git add --patch`, reviewing changes in long lines can be
> > difficult with the default line-based diff. This is particularly
> > noticeable in formats such as JSONP, CSV, LaTeX, Markdown, or other
> > plain text where small inline edits can be hard to spot.
> >
> > Added `w - print the current hunk with word-diff` during hunk selection
> > to re-display the current hunk using `--word-diff`. This provides a
> > clearer inline view of changes without modifying the hunk or affecting
> > how patches are applied or staged.
>
> I think this is useful. While one can set interactive.diffFilter to
> highlight intraline differences with "diff-highlight" or "delta" they do
> not cope well if the text has been reflowed.

I concur, though I wonder what other diff options would be useful. I can imagine a world where "add --patch" allows to reshow the patch with any set of custom options. Spitballing…

     :show <opts>

…could work, since we have room to allow long-form commands still. This could be extended to arbitrary git-* commands, and ":!cmd" could be used for shelling out.

(Can you tell I use Vim?)

Anyway, what I like about this is we don't have to worry about running out of (or thinking up new mnemonics for) single letters for different combinations of diff options, so it's a bit more extensible.

Show 13 quoted lines
> I think the approach of using the current hunk text, rather than running
> "git diff --diff-words" is sensible because it works correctly if the
> user has edited the hunk and it makes it easy to handle hunks that have
> been split. It would be good to propagate the filename when creating the
> filespec so that we use the correct word diff regex for the file. We
> should also propagate the context and inter-hunk context settings from
> struct interactive_options. It would also be a good idea to reuse the
> hunk header from the unified diff so that the line numbers and hunk
> fragment are correct.
>
> Thanks
>
> Phillip
-- 
D. Ben Knoble
Previous: Phillip WoodNext: Junio C Hamano
Message 6 of 9 in “add -p: introduce 'w' command to view hunk with --word-diff”
  1. add -p: introduce 'w' command to view hunk with --word-diffJavier Bassi, May 6, 2026
  2. PabloMay 7, 2026
  3. Phillip WoodMay 7, 2026
  4. PabloMay 7, 2026
  5. Phillip WoodMay 7, 2026
  6. D. Ben KnobleMay 7, 2026
  7. Junio C HamanoMay 11, 2026
  8. D. Ben KnobleMay 11, 2026
  9. Junio C HamanoMay 12, 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.