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

Re: git add -p with new file

From
Jeff King <peff@peff.net>
Date
Dec 11, 2016, 13:00 UTC
Message-ID
<20161211130034.ygj5l2gbx33uknlk@sigill.intra.peff.net>
In-Reply-To
<xmqq37hvphji.fsf@gitster.mtv.corp.google.com>
On Sat, Dec 10, 2016 at 02:04:33PM -0800, Junio C Hamano wrote:
Show 19 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> > On Fri, Dec 09, 2016 at 01:43:24PM -0500, Ariel wrote:
> > ...
> >> But it doesn't have to be that way. You could make add -p identical to add
> >> without options, except the -p prompts to review diffs first.
> >
> > The question is whether you would annoy people using "-p" if you started
> > including untracked files by default. I agree because it's inherently an
> > interactive process that we can be looser with backwards compatibility.
> 
> It might be interactive, but it will be irritating that we suddenly
> have to see hundreds of lines in an untracked file before we are
> asked to say "no I do not want to add this file" and have to do so
> for all the untracked files that happen to match the given pathspec.
> 
> It might make it less irritating if one of the interactive choices
> offered in the first prompt were N that tells the command: "No,
> ignore all the untracked paths", though.  I dunno.

Yeah, I agree dumping the contents automatically is annoying. Ariel suggested asking twice about each path, which sounds clunky to me. I'd probably give a simple question, with an option to dump the contents. Like:

  $ echo foo >untracked
  $ git add -p
  New file: untracked
  Stage this file [y,n,v,q,a,d,/,e,?]? v     <-- user types 'v' for "view"
  diff --git a/untracked b/untracked
  index e69de29..257cc56 100644
  --- a/untracked
  +++ b/untracked
  @@ -0,0 +1 @@
  +foo
  Stage this file [y,n,v,q,a,d,/,e?]? y

Alternatively, "v" could just run "$GIT_PAGER <file>". The point is to refresh your memory on what is in it before making a decision.

I'd also probably add interactive.showUntracked to make the whole thing optional (but I think it would be OK to default it to on).

Some thought would have to be given handling binary files, as we wouldn't want to dump their contents (but maybe showing them in a pager would be OK).. We skip them entirely right now. So a related feature may be asking "Stage this file" for binary files, with an option to somehow view the contents.

I don't have plans to work on any of this myself. Just dumping thoughts on what I'd expect an implementation to deal with.

-Peff
Previous: Junio C HamanoNext: Stephan Beyer
Message 9 of 17 in “git add -p with new file”
  1. ArielDec 7, 2016
  2. Duy NguyenDec 7, 2016
  3. ArielDec 9, 2016
  4. Stephan BeyerDec 12, 2016
  5. Jeff KingDec 9, 2016
  6. ArielDec 9, 2016
  7. Jeff KingDec 10, 2016
  8. Junio C HamanoDec 10, 2016
  9. Jeff KingDec 11, 2016
  10. Stephan BeyerDec 12, 2016
  11. Jeff KingDec 13, 2016
  12. Junio C HamanoDec 13, 2016
  13. Jeff KingDec 13, 2016
  14. Junio C HamanoDec 13, 2016
  15. git add -p with unmerged files (was: git add -p with new file)Stephan Beyer, Dec 13, 2016
  16. Jeff KingDec 13, 2016
  17. Junio C HamanoDec 13, 2016

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.