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

Re: Staging commits with visual diff tools?

From
Jeff King <peff@peff.net>
Date
May 27, 2015, 07:28 UTC
Message-ID
<20150527072826.GC6898@peff.net>
In-Reply-To
<alpine.DEB.2.10.1505262147230.3709@alice>
On Tue, May 26, 2015 at 09:50:49PM +0100, John Lee wrote:
Show 9 quoted lines
> Does anybody have code to stage commits using a the visual diff/merge tools
> supported by git-difftool?  Is there support in git itself somewhere, even?
> 
> I'm looking for something functionally similar to git add -p
> 
> Looking at the git-difftool source I can see how to write a command to do
> it, but wanted to check if it had already been implemented.
> 
> Did I miss a way that already exists?

git-gui has a visual staging tool, and I think some other git interfaces do, too (e.g., tig). But I don't think there is a way to interact with an arbitrary 3rd-party diff tool. I would think doing so would depend on the diff tool itself; what facility does it provide for picking lines or a hunk out of a diff and communicating it back to git to stage?

If you are interested in looking further, see how the %patch_mode hash is defined in git-add--interactive.perl. Specifically, note that "add -p" is just one case: diff against the index and apply with "apply --cached". But once you have a separate tool for picking hunks, you should be able to drop in the different DIFF/APPLY pairs to implement "checkout -p", etc.

-Peff
Previous: John LeeNext: John Lee
Message 2 of 10 in “Staging commits with visual diff tools?”
  1. John LeeMay 26, 2015
  2. Jeff KingMay 27, 2015
  3. John LeeMay 27, 2015
  4. Michael J GruberMay 29, 2015
  5. David AguilarMay 31, 2015
  6. John LeeMay 31, 2015
  7. David AguilarJun 1, 2015
  8. John LeeJun 1, 2015
  9. John LeeJun 27, 2015
  10. John LeeJun 28, 2015

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.