Documentation / git-add.txton commit Merge branch 'maint' (3545193)
   1git-add(1)
   2==========
   3
   4NAME
   5----
   6git-add - Add file contents to the changeset to be committed next
   7
   8SYNOPSIS
   9--------
  10'git-add' [-n] [-v] [-f] [--interactive | -i] [-u] [--] <file>...
  11
  12DESCRIPTION
  13-----------
  14All the changed file contents to be committed together in a single set
  15of changes must be "added" with the 'add' command before using the
  16'commit' command.  This is not only for adding new files.  Even modified
  17files must be added to the set of changes about to be committed.
  18
  19This command can be performed multiple times before a commit. The added
  20content corresponds to the state of specified file(s) at the time the
  21'add' command is used. This means the 'commit' command will not consider
  22subsequent changes to already added content if it is not added again before
  23the commit.
  24
  25The 'git status' command can be used to obtain a summary of what is included
  26for the next commit.
  27
  28This command can be used to add ignored files with `-f` (force)
  29option, but they have to be
  30explicitly and exactly specified from the command line.  File globbing
  31and recursive behaviour do not add ignored files.
  32
  33Please see gitlink:git-commit[1] for alternative ways to add content to a
  34commit.
  35
  36
  37OPTIONS
  38-------
  39<file>...::
  40        Files to add content from.  Fileglobs (e.g. `*.c`) can
  41        be given to add all matching files.  Also a
  42        leading directory name (e.g. `dir` to add `dir/file1`
  43        and `dir/file2`) can be given to add all files in the
  44        directory, recursively.
  45
  46-n::
  47        Don't actually add the file(s), just show if they exist.
  48
  49-v::
  50        Be verbose.
  51
  52-f::
  53        Allow adding otherwise ignored files.
  54
  55-i, \--interactive::
  56        Add modified contents in the working tree interactively to
  57        the index.
  58
  59-u::
  60        Update only files that git already knows about. This is similar
  61        to what "git commit -a" does in preparation for making a commit,
  62        except that the update is limited to paths specified on the
  63        command line. If no paths are specified, all tracked files are
  64        updated.
  65
  66\--::
  67        This option can be used to separate command-line options from
  68        the list of files, (useful when filenames might be mistaken
  69        for command-line options).
  70
  71
  72EXAMPLES
  73--------
  74git-add Documentation/\\*.txt::
  75
  76        Adds content from all `\*.txt` files under `Documentation`
  77        directory and its subdirectories.
  78+
  79Note that the asterisk `\*` is quoted from the shell in this
  80example; this lets the command to include the files from
  81subdirectories of `Documentation/` directory.
  82
  83git-add git-*.sh::
  84
  85        Considers adding content from all git-*.sh scripts.
  86        Because this example lets shell expand the asterisk
  87        (i.e. you are listing the files explicitly), it does not
  88        consider `subdir/git-foo.sh`.
  89
  90Interactive mode
  91----------------
  92When the command enters the interactive mode, it shows the
  93output of the 'status' subcommand, and then goes into its
  94interactive command loop.
  95
  96The command loop shows the list of subcommands available, and
  97gives a prompt "What now> ".  In general, when the prompt ends
  98with a single '>', you can pick only one of the choices given
  99and type return, like this:
 100
 101------------
 102    *** Commands ***
 103      1: status       2: update       3: revert       4: add untracked
 104      5: patch        6: diff         7: quit         8: help
 105    What now> 1
 106------------
 107
 108You also could say "s" or "sta" or "status" above as long as the
 109choice is unique.
 110
 111The main command loop has 6 subcommands (plus help and quit).
 112
 113status::
 114
 115   This shows the change between HEAD and index (i.e. what will be
 116   committed if you say "git commit"), and between index and
 117   working tree files (i.e. what you could stage further before
 118   "git commit" using "git-add") for each path.  A sample output
 119   looks like this:
 120+
 121------------
 122              staged     unstaged path
 123     1:       binary      nothing foo.png
 124     2:     +403/-35        +1/-1 git-add--interactive.perl
 125------------
 126+
 127It shows that foo.png has differences from HEAD (but that is
 128binary so line count cannot be shown) and there is no
 129difference between indexed copy and the working tree
 130version (if the working tree version were also different,
 131'binary' would have been shown in place of 'nothing').  The
 132other file, git-add--interactive.perl, has 403 lines added
 133and 35 lines deleted if you commit what is in the index, but
 134working tree file has further modifications (one addition and
 135one deletion).
 136
 137update::
 138
 139   This shows the status information and gives prompt
 140   "Update>>".  When the prompt ends with double '>>', you can
 141   make more than one selection, concatenated with whitespace or
 142   comma.  Also you can say ranges.  E.g. "2-5 7,9" to choose
 143   2,3,4,5,7,9 from the list.  You can say '*' to choose
 144   everything.
 145+
 146What you chose are then highlighted with '*',
 147like this:
 148+
 149------------
 150           staged     unstaged path
 151  1:       binary      nothing foo.png
 152* 2:     +403/-35        +1/-1 git-add--interactive.perl
 153------------
 154+
 155To remove selection, prefix the input with `-`
 156like this:
 157+
 158------------
 159Update>> -2
 160------------
 161+
 162After making the selection, answer with an empty line to stage the
 163contents of working tree files for selected paths in the index.
 164
 165revert::
 166
 167  This has a very similar UI to 'update', and the staged
 168  information for selected paths are reverted to that of the
 169  HEAD version.  Reverting new paths makes them untracked.
 170
 171add untracked::
 172
 173  This has a very similar UI to 'update' and
 174  'revert', and lets you add untracked paths to the index.
 175
 176patch::
 177
 178  This lets you choose one path out of 'status' like selection.
 179  After choosing the path, it presents diff between the index
 180  and the working tree file and asks you if you want to stage
 181  the change of each hunk.  You can say:
 182
 183       y - add the change from that hunk to index
 184       n - do not add the change from that hunk to index
 185       a - add the change from that hunk and all the rest to index
 186       d - do not the change from that hunk nor any of the rest to index
 187       j - do not decide on this hunk now, and view the next
 188           undecided hunk
 189       J - do not decide on this hunk now, and view the next hunk
 190       k - do not decide on this hunk now, and view the previous
 191           undecided hunk
 192       K - do not decide on this hunk now, and view the previous hunk
 193+
 194After deciding the fate for all hunks, if there is any hunk
 195that was chosen, the index is updated with the selected hunks.
 196
 197diff::
 198
 199  This lets you review what will be committed (i.e. between
 200  HEAD and index).
 201
 202
 203See Also
 204--------
 205gitlink:git-status[1]
 206gitlink:git-rm[1]
 207gitlink:git-mv[1]
 208gitlink:git-commit[1]
 209gitlink:git-update-index[1]
 210
 211Author
 212------
 213Written by Linus Torvalds <torvalds@osdl.org>
 214
 215Documentation
 216--------------
 217Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
 218
 219GIT
 220---
 221Part of the gitlink:git[7] suite
 222