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
Jeff King <peff@peff.net>
Date
Jan 10, 2012, 18:38 UTC
Message-ID
<20120110183833.GA15787@sigill.intra.peff.net>
In-Reply-To
<7vpqer9znv.fsf@alter.siamese.dyndns.org>
On Tue, Jan 10, 2012 at 10:32:20AM -0800, Junio C Hamano wrote:
Show 9 quoted lines
> Thomas Rast <trast@student.ethz.ch> writes:
> 
> > A not-so-proper solution might of course start by looking at which files
> > are untracked, and only run the 'git add -N' immediately before patch
> > application.
> 
> Isn't the real issue that we mistakenly gave an impression that "add -p"
> is the primary interface to the users, and forgot to tell them about the
> more general "add -i", which "add -p" is a small subset of?

Maybe it is just me, but I find "add -p" insanely useful, and the rest of "add -i" to be worthless clutter. The "add -p" functionality is not easily available anywhere else, but the rest of "add -i" can be easily (and often more efficiently) mimicked using existing git commands.

> 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. I think it is simply a nice workflow to do:

  $ hack hack hack
  $ git add -p ;# inspect and add changes
  $ git commit
which is very similar to the traditional git workflow:
  $ hack hack hack
  $ git diff ;# inspect changes
  $ git add foo ;# add changes
  $ git commit

I find myself using "add -p" almost exclusively these days, as it combines the two middle steps (and even though I usually am just hitting "y" after inspection, when I _do_ want to make a change, I am right there in the hunk selection loop already).

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 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.