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

Re: "git add -p" versus "git add -i", followed by "p"

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Dec 2, 2018, 16:56 UTC
Message-ID
<20181202165617.GG30222@szeder.dev>
In-Reply-To
<alpine.LFD.2.21.1812021124350.5509@localhost.localdomain>
On Sun, Dec 02, 2018 at 11:30:19AM -0500, Robert P. J. Day wrote:
Show 30 quoted lines
> 
>   testing adding by patch for the very first time (i've just never
> needed this), and reading the "progit" book and reading the man page,
> and the impression i'm getting is that running "git add -p" (going
> straight to patch mode) is supposed to be equivalent to running "git
> add -i", then typing "p" to switch to patch mode.
> 
>   that is most emphatically not what i'm seeing. if i run "git add
> -p", then i get to what i expect -- the patch subsystem:
> 
>   $ git add -p
>   diff --git a/README.asc b/README.asc
>   index fa40bad..840e85b 100644
>   --- a/README.asc
>   +++ b/README.asc
>   @@ -1,3 +1,9 @@
>   +change 1
>   +
>   +
>   +
>   +
>   +
>    = Pro Git, Second Edition
> 
>    Welcome to the second edition of the Pro Git book.
>   Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]?
> 
> but if i start with "git add -i", there seems to be no way to get to
> patch mode -- certainly "p" doesn't do it. am i stupidly missing
> something trivial? is the explanation misleading or inncomplete?
Worksforme™:
  $ echo "New content" >>README.md 
  $ echo "New content" >>t/README
  $ echo "New content" >>contrib//README
  $ git add -i
             staged     unstaged path
    1:    unchanged        +1/-0 README.md
    2:    unchanged        +1/-0 contrib/README
    3:    unchanged        +1/-0 t/README
  
  *** Commands ***
    1: status       2: update       3: revert       4: add untracked
    5: patch        6: diff         7: quit         8: help
  What now> p
             staged     unstaged path
    1:    unchanged        +1/-0 README.md
    2:    unchanged        +1/-0 contrib/README
    3:    unchanged        +1/-0 t/README
  Patch update>> 1
             staged     unstaged path
  * 1:    unchanged        +1/-0 README.md
    2:    unchanged        +1/-0 contrib/README
    3:    unchanged        +1/-0 t/README
  Patch update>> 2
             staged     unstaged path
  * 1:    unchanged        +1/-0 README.md
  * 2:    unchanged        +1/-0 contrib/README
    3:    unchanged        +1/-0 t/README
  Patch update>> 
Here I hit enter.  Did you?
  diff --git a/README.md b/README.md
  index f920a42fad..63dee5cfc3 100644
  --- a/README.md
  +++ b/README.md
  @@ -62,3 +62,4 @@ and the name as (depending on your mood):
   [Documentation/giteveryday.txt]: Documentation/giteveryday.txt
   [Documentation/gitcvs-migration.txt]:
  Documentation/gitcvs-migration.txt
   [Documentation/SubmittingPatches]: Documentation/SubmittingPatches
  +New content
  Stage this hunk [y,n,q,a,d,e,?]? y
  
  diff --git a/contrib/README b/contrib/README
  index 05f291c1f1..2b152dfcff 100644
  --- a/contrib/README
  +++ b/contrib/README
  @@ -41,3 +41,4 @@ submit a patch to create a subdirectory of contrib/
  and put your
   stuff there.
   
   -jc
  +New content
  Stage this hunk [y,n,q,a,d,e,?]? n
  
  *** Commands ***
    1: status       2: update       3: revert       4: add untracked
    5: patch        6: diff         7: quit         8: help
  What now> q
  Bye.
  $ git diff --cached 
  diff --git a/README.md b/README.md
  index f920a42fad..63dee5cfc3 100644
  --- a/README.md
  +++ b/README.md
  @@ -62,3 +62,4 @@ and the name as (depending on your mood):
   [Documentation/giteveryday.txt]: Documentation/giteveryday.txt
   [Documentation/gitcvs-migration.txt]: Documentation/gitcvs-migration.txt
   [Documentation/SubmittingPatches]: Documentation/SubmittingPatches
  +New content
  $

Arguably the documentation could make it clear that the user can choose multiple files at once, e.g.:

diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
index c9623854bf..061f9cbb0d 100644
--- a/Documentation/git-add.txt
+++ b/Documentation/git-add.txt
@@ -317,9 +317,9 @@ add untracked::
 
 patch::
 
-  This lets you choose one path out of a 'status' like selection.
-  After choosing the path, it presents the diff between the index
-  and the working tree file and asks you if you want to stage
+  This lets you choose one or more paths out of a 'status' like selection.
+  After choosing the path(s), it presents the diff between the index
+  and the working tree file(s) and asks you if you want to stage
   the change of each hunk.  You can select one of the following
   options and type return:
 
And perhaps we could have a dedicated menu entry for "I'm done with
selecting paths"?  Dunno; I'm a 'git add -p' user myself.
Previous: Robert P. J. DayNext: Robert P. J. Day
Message 2 of 9 in “"git add -p" versus "git add -i", followed by "p"”
  1. Robert P. J. DayDec 2, 2018
  2. SZEDER GáborDec 2, 2018
  3. Robert P. J. DayDec 2, 2018
  4. Robert P. J. DayDec 2, 2018
  5. Duy NguyenDec 2, 2018
  6. Robert P. J. DayDec 2, 2018
  7. Robert P. J. DayDec 8, 2018
  8. Kevin DaudtDec 2, 2018
  9. Robert P. J. DayDec 2, 2018

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.