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

Re: feature request: git add--interactive --patch on regex-matched hunks only

From
Jeff King <peff@peff.net>
Date
Jul 27, 2011, 08:10 UTC
Message-ID
<20110727081034.GB8105@sigill.intra.peff.net>
In-Reply-To
<CACsJy8C822Fvwav4Wpw4e-12ZY20XM1s2v4KymZkaDYLxkMHvw@mail.gmail.com>
On Tue, Jul 26, 2011 at 08:03:01PM +0700, Nguyen Thai Ngoc Duy wrote:
Show 6 quoted lines
> It would be even more cool if --hunks (or whatever the name will be)
> could work without -p. I mean, if "git diff" supports it, then I can
> fine tune my regex to meet a selection of hunks I want, and verify it
> really is what I want. Then "git add --hunks=magic" and voila! (The
> "git add --hunks" without -p surely can be workaround by adding "-p",
> then accept all hunks).

Yeah, doing "yes | git add -p --hunks=foo" would probably do what you want. But you don't really have a good way of verifying what it will add (you could check after the fact what's left in "git diff", or what's now in "git diff --cached", of course).

> And if diff machinery learns this, we would have "git log --hunks" too.
> 
> OK I'm asking too much..
Probably. :)

I'm not sure how useful "log --hunks" would be. The changes you commit don't tend to be that big (well, not if you're doing it right). It seems much more likely to have the case you brought up, which is that some file has a bunch of boring boilerplate that doesn't need to be changed, and you need to pick out the interesting changes from the boilerplate changes.

I suppose if somebody committed all of the boilerplate changes (like .po comment changes), then you would want to be able to pick them apart. But that just seems like the wrong thing (i.e., if those comments really are uninteresting, they should not be committed). But I don't work with .po files at all, so maybe there is a good reason to commit them.

-Peff
Previous: Nguyen Thai Ngoc DuyNext: Nguyen Thai Ngoc Duy
Message 11 of 19 in “feature request: git add--interactive --patch on regex-matched hunks only”
  1. Nguyen Thai Ngoc DuyJul 24, 2011
  2. Jeff KingJul 25, 2011
  3. Junio C HamanoJul 25, 2011
  4. Jeff KingJul 26, 2011
  5. Nguyen Thai Ngoc DuyJul 26, 2011
  6. Jeff KingJul 26, 2011
  7. Nguyen Thai Ngoc DuyJul 26, 2011
  8. Jeff KingJul 26, 2011
  9. Nguyen Thai Ngoc DuyJul 26, 2011
  10. Nguyen Thai Ngoc DuyJul 26, 2011
  11. Jeff KingJul 27, 2011
  12. Nguyen Thai Ngoc DuyJul 27, 2011
  13. Jeff KingJul 27, 2011
  14. Jeff KingJul 27, 2011
  15. 1/5 add--interactive: refactor patch mode argument processingJeff King, Jul 27, 2011
  16. 2/5 add--interactive: factor out regex error handlingJeff King, Jul 27, 2011
  17. 3/5 add--interactive: allow hunk filtering on command lineJeff King, Jul 27, 2011
  18. 4/5 add--interactive: allow negatation of hunk filtersJeff King, Jul 27, 2011
  19. 5/5 add--interactive: add option to autosplit hunksJeff King, Jul 27, 2011

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.