Home Explore Blog CI



git

4th chunk of `Documentation/git-add.adoc`
bcefe5006e2ccb2907a706162b792ee876f93ecd286bd2320000000100000e51
 the command enters the interactive mode, it shows the
output of the 'status' subcommand, and then goes into its
interactive command loop.

The command loop shows the list of subcommands available, and
gives a prompt "What now> ".  In general, when the prompt ends
with a single '>', you can pick only one of the choices given
and type return, like this:

------------
    *** Commands ***
      1: status       2: update       3: revert       4: add untracked
      5: patch        6: diff         7: quit         8: help
    What now> 1
------------

You also could say `s` or `sta` or `status` above as long as the
choice is unique.

The main command loop has 6 subcommands (plus help and quit).

status::

   This shows the change between `HEAD` and index (i.e. what will be
   committed if you say `git commit`), and between index and
   working tree files (i.e. what you could stage further before
   `git commit` using `git add`) for each path.  A sample output
   looks like this:
+
------------
              staged     unstaged path
     1:       binary      nothing foo.png
     2:     +403/-35        +1/-1 add-interactive.c
------------
+
It shows that `foo.png` has differences from `HEAD` (but that is
binary so line count cannot be shown) and there is no
difference between indexed copy and the working tree
version (if the working tree version were also different,
'binary' would have been shown in place of 'nothing').  The
other file, `add-interactive.c`, has 403 lines added
and 35 lines deleted if you commit what is in the index, but
working tree file has further modifications (one addition and
one deletion).

update::

   This shows the status information and issues an "Update>>"
   prompt.  When the prompt ends with double '>>', you can
   make more than one selection, concatenated with whitespace or
   comma.  Also you can say ranges.  E.g. "2-5 7,9" to choose
   2,3,4,5,7,9 from the list.  If the second number in a range is
   omitted, all remaining patches are taken.  E.g. "7-" to choose
   7,8,9 from the list.  You can say '*' to choose everything.
+
What you chose are then highlighted with '*',
like this:
+
------------
           staged     unstaged path
  1:       binary      nothing foo.png
* 2:     +403/-35        +1/-1 add-interactive.c
------------
+
To remove selection, prefix the input with `-`
like this:
+
------------
Update>> -2
------------
+
After making the selection, answer with an empty line to stage the
contents of working tree files for selected paths in the index.

revert::

  This has a very similar UI to 'update', and the staged
  information for selected paths are reverted to that of the
  HEAD version.  Reverting new paths makes them untracked.

add untracked::

  This has a very similar UI to 'update' and
  'revert', and lets you add untracked paths to the index.

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
  the change of each hunk.  You can select one of the following
  options and type return:

       y - stage this hunk
       n - do not stage this hunk
       q - quit; do not stage this hunk or any of the remaining ones
       a - stage this hunk and all later hunks in the file
       d - do not stage this hunk or any of the later hunks in the file
       g - select a hunk to go to
       / - search for a hunk matching the given regex
       j - leave this hunk undecided, see next undecided hunk
       J - leave this hunk undecided, see next hunk
       k - leave this hunk undecided, see previous undecided hunk

Title: Git Add Interactive Mode
Summary
The git add interactive mode provides a command loop with various subcommands, including status, update, revert, add untracked, patch, diff, quit, and help, allowing users to stage changes, view differences, and manage files in the index and working tree, with features like selecting multiple files, searching, and choosing hunks to stage.