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

Re: Please support add -p with a new file, to add only part of the file

From
Josh Triplett <josh@joshtriplett.org>
Date
Jan 10, 2012, 22:29 UTC
Message-ID
<20120110222926.GB14895@leaf>
In-Reply-To
<20120110193857.GA19665@sigill.intra.peff.net>
On Tue, Jan 10, 2012 at 02:38:57PM -0500, Jeff King wrote:
Show 17 quoted lines
> On Tue, Jan 10, 2012 at 11:33:39AM -0800, Junio C Hamano wrote:
> 
> > Jeff King <peff@peff.net> writes:
> > 
> > >> Even if you start with "add -N", there won't be individual "hunks" you can
> > >> pick and choose from diffing emptiness and the whole new file, so you end
> > >> up using "edit hunk" interface.
> > >
> > > I don't think the main impetus for this is that people necessarily want
> > > to pick and choose hunks from added files.
> > 
> > Well, read the subject of your e-mail and tell me what it says ;-)
> 
> Heh. Oops.
> 
> Yes, I agree that "add -p" is not especially useful for that case, and
> the workflow I was describing is very different[1].

I've gotten used to editing diffs directly, and when I just want to include subsets of a file on a chunk-by-chunk basis (for instance, one new function but not another new function), I'd find it a lot easier and less error-prone to "git add -p newfile" and edit a diff than to copy the file aside, edit the original to delete pieces I don't want, add, commit, and copy the file back.

Most importantly, I want to use "git add -p" because I know it'll *never* modify my working copy, only the index. I find that a useful safety property.

Apart from that, it also means I have less mental state to track ("remember to copy the original file back later").

- Josh Triplett
Previous: Jeff King
Message 7 of 7 in “Re: Please support add -p with a new file, to add only part of the file”
  1. Jonathan NiederJan 9, 2012
  2. Thomas RastJan 10, 2012
  3. Junio C HamanoJan 10, 2012
  4. Jeff KingJan 10, 2012
  5. Junio C HamanoJan 10, 2012
  6. Jeff KingJan 10, 2012
  7. Josh TriplettJan 10, 2012

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.