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

Re: Can `add --patch` display the diff in my difftool instead of just printing it on the command line?

From
Jeff King <peff@peff.net>
Date
Dec 14, 2010, 21:38 UTC
Message-ID
<20101214213810.GB2216@sigill.intra.peff.net>
In-Reply-To
<AANLkTi=_VyUAL+qjWLEcThX-zC5n0v0WB-W7hTSZn0ae@mail.gmail.com>
On Tue, Dec 14, 2010 at 03:17:09PM -0600, Dun Peal wrote:
Show 5 quoted lines
> I'd like to display the diff of each modified working copy file, and
> have the option of staging (or reversing) each patch after it is
> displayed. This is exactly the same thing `add --patch` does, except I
> want the diff to be displayed in my difftool (happens to be vimdiff)
> rather than just being printed.

You can't do this with "git add -p" now, but I suspect the patch would be relatively straightforward. See patch_update_file in git-add--interactive.perl. You just need to replace:

  for (@{$head->{DISPLAY}}) {
    print;
  }

with code to dump the diff in @{$head->{TEXT}} either to stdin of your display program or to a tempfile that your program operates on. Conditional on having some config option to specify your program, of course.

Or did you want something more integrated with vimdiff? If you want to primarily see the diff in vim and then have mappings set up to stage or revert changes, that is pretty straightforward to do. Just have vim dump the relevant hunk to "git apply --cached" or "git apply -R". I would be surprised if the vim integration packages didn't have something like this already.

-Peff
Previous: Dun PealNext: Dun Peal
Message 2 of 3 in “Can `add --patch` display the diff in my difftool instead of just printing it on the command line?”
  1. Dun PealDec 14, 2010
  2. Jeff KingDec 14, 2010
  3. Dun PealDec 14, 2010

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.