1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <!DOCTYPE sect2 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
\r
4 <sect2 lang="en" id="git-add(1)">
\r
5 <title>git-add(1)</title>
\r
7 <primary>git-add(1)</primary>
\r
9 <simplesect id="git-add(1)__name">
\r
11 <simpara>git-add - Add file contents to the index</simpara>
\r
13 <simplesect id="git-add(1)__synopsis">
\r
14 <title>SYNOPSIS</title>
\r
16 <literallayout><emphasis>git add</emphasis> [-n] [-v] [--force | -f] [--interactive | -i] [--patch | -p]
\r
17 [--edit | -e] [--all | [--update | -u]] [--intent-to-add | -N]
\r
18 [--refresh] [--ignore-errors] [--ignore-missing] [--]
\r
19 [<filepattern>…]</literallayout>
\r
22 <simplesect id="git-add(1)__description">
\r
23 <title>DESCRIPTION</title>
\r
24 <simpara>This command updates the index using the current content found in
\r
25 the working tree, to prepare the content staged for the next commit.
\r
26 It typically adds the current content of existing paths as a whole,
\r
27 but with some options it can also be used to add content with
\r
28 only part of the changes made to the working tree files applied, or
\r
29 remove paths that do not exist in the working tree anymore.</simpara>
\r
30 <simpara>The "index" holds a snapshot of the content of the working tree, and it
\r
31 is this snapshot that is taken as the contents of the next commit. Thus
\r
32 after making any changes to the working directory, and before running
\r
33 the commit command, you must use the <emphasis>add</emphasis> command to add any new or
\r
34 modified files to the index.</simpara>
\r
35 <simpara>This command can be performed multiple times before a commit. It only
\r
36 adds the content of the specified file(s) at the time the add command is
\r
37 run; if you want subsequent changes included in the next commit, then
\r
38 you must run <emphasis>git add</emphasis> again to add the new content to the index.</simpara>
\r
39 <simpara>The <emphasis>git status</emphasis> command can be used to obtain a summary of which
\r
40 files have changes that are staged for the next commit.</simpara>
\r
41 <simpara>The <emphasis>git add</emphasis> command will not add ignored files by default. If any
\r
42 ignored files were explicitly specified on the command line, <emphasis>git add</emphasis>
\r
43 will fail with a list of ignored files. Ignored files reached by
\r
44 directory recursion or filename globbing performed by Git (quote your
\r
45 globs before the shell) will be silently ignored. The <emphasis>git add</emphasis> command can
\r
46 be used to add ignored files with the <emphasis>-f</emphasis> (force) option.</simpara>
\r
47 <simpara>Please see <xref linkend="git-commit(1)" /> for alternative ways to add content to a
\r
50 <simplesect id="git-add(1)__options">
\r
51 <title>OPTIONS</title>
\r
55 <filepattern>…
\r
59 Files to add content from. Fileglobs (e.g. <emphasis>*.c</emphasis>) can
\r
60 be given to add all matching files. Also a
\r
61 leading directory name (e.g. <emphasis>dir</emphasis> to add <emphasis>dir/file1</emphasis>
\r
62 and <emphasis>dir/file2</emphasis>) can be given to add all files in the
\r
63 directory, recursively.
\r
76 Don't actually add the file(s), just show if they exist and/or will
\r
103 Allow adding otherwise ignored files.
\r
116 Add modified contents in the working tree interactively to
\r
117 the index. Optional path arguments may be supplied to limit
\r
118 operation to a subset of the working tree. See Interactive
\r
132 Interactively choose hunks of patch between the index and the
\r
133 work tree and add them to the index. This gives the user a chance
\r
134 to review the difference before adding modified contents to the
\r
137 <simpara>This effectively runs <emphasis>add --interactive</emphasis>, but bypasses the
\r
138 initial command menu and directly jumps to the <emphasis>patch</emphasis> subcommand.
\r
139 See Interactive mode for details.</simpara>
\r
148 Open the diff vs. the index in an editor and let the user
\r
149 edit it. After the editor was closed, adjust the hunk headers
\r
150 and apply the patch to the index.
\r
152 <simpara>The intent of this option is to pick and choose lines of the patch to
\r
153 apply, or even to modify the contents of lines to be staged. This can be
\r
154 quicker and more flexible than using the interactive hunk selector.
\r
155 However, it is easy to confuse oneself and create a patch that does not
\r
156 apply to the index. See EDITING PATCHES below.</simpara>
\r
168 Only match <filepattern> against already tracked files in
\r
169 the index rather than the working tree. That means that it
\r
170 will never stage new files, but that it will stage modified
\r
171 new contents of tracked files and that it will remove files
\r
172 from the index if the corresponding files in the working tree
\r
175 <simpara>If no <filepattern> is given, default to "."; in other words,
\r
176 update all tracked files in the current directory and its
\r
177 subdirectories.</simpara>
\r
189 Like <emphasis>-u</emphasis>, but match <filepattern> against files in the
\r
190 working tree in addition to the index. That means that it
\r
191 will find new files as well as staging modified content and
\r
192 removing files that are no longer in the working tree.
\r
205 Record only the fact that the path will be added later. An entry
\r
206 for the path is placed in the index with no content. This is
\r
207 useful for, among other things, showing the unstaged content of
\r
208 such files with <emphasis>git diff</emphasis> and committing them with <emphasis>git commit
\r
219 Don't add the file(s), but only refresh their stat()
\r
220 information in the index.
\r
230 If some files could not be added because of errors indexing
\r
231 them, do not abort the operation, but continue adding the
\r
232 others. The command shall still exit with non-zero status.
\r
233 The configuration variable <emphasis>add.ignoreErrors</emphasis> can be set to
\r
234 true to make this the default behaviour.
\r
244 This option can only be used together with --dry-run. By using
\r
245 this option the user can check if any of the given files would
\r
246 be ignored, no matter if they are already present in the work
\r
257 This option can be used to separate command-line options from
\r
258 the list of files, (useful when filenames might be mistaken
\r
259 for command-line options).
\r
265 <simplesect id="git-add(1)__configuration">
\r
266 <title>Configuration</title>
\r
267 <simpara>The optional configuration variable <emphasis>core.excludesfile</emphasis> indicates a path to a
\r
268 file containing patterns of file names to exclude from git-add, similar to
\r
269 $GIT_DIR/info/exclude. Patterns in the exclude file are used in addition to
\r
270 those in info/exclude. See <xref linkend="gitignore(5)" />.</simpara>
\r
272 <simplesect id="git-add(1)__examples">
\r
273 <title>EXAMPLES</title>
\r
277 Adds content from all <emphasis>*.txt</emphasis> files under <emphasis>Documentation</emphasis> directory
\r
278 and its subdirectories:
\r
280 <screen>$ git add Documentation/\*.txt</screen>
\r
281 <simpara>Note that the asterisk <emphasis>*</emphasis> is quoted from the shell in this
\r
282 example; this lets the command include the files from
\r
283 subdirectories of <emphasis>Documentation/</emphasis> directory.</simpara>
\r
287 Considers adding content from all git-*.sh scripts:
\r
289 <screen>$ git add git-*.sh</screen>
\r
290 <simpara>Because this example lets the shell expand the asterisk (i.e. you are
\r
291 listing the files explicitly), it does not consider
\r
292 <emphasis>subdir/git-foo.sh</emphasis>.</simpara>
\r
296 <simplesect id="git-add(1)__interactive_mode">
\r
297 <title>Interactive mode</title>
\r
298 <simpara>When the command enters the interactive mode, it shows the
\r
299 output of the <emphasis>status</emphasis> subcommand, and then goes into its
\r
300 interactive command loop.</simpara>
\r
301 <simpara>The command loop shows the list of subcommands available, and
\r
302 gives a prompt "What now> ". In general, when the prompt ends
\r
303 with a single <emphasis>></emphasis>, you can pick only one of the choices given
\r
304 and type return, like this:</simpara>
\r
305 <screen> *** Commands ***
\r
306 1: status 2: update 3: revert 4: add untracked
\r
307 5: patch 6: diff 7: quit 8: help
\r
308 What now> 1</screen>
\r
309 <simpara>You also could say <emphasis>s</emphasis> or <emphasis>sta</emphasis> or <emphasis>status</emphasis> above as long as the
\r
310 choice is unique.</simpara>
\r
311 <simpara>The main command loop has 6 subcommands (plus help and quit).</simpara>
\r
319 This shows the change between HEAD and index (i.e. what will be
\r
320 committed if you say <emphasis>git commit</emphasis>), and between index and
\r
321 working tree files (i.e. what you could stage further before
\r
322 <emphasis>git commit</emphasis> using <emphasis>git add</emphasis>) for each path. A sample output
\r
325 <screen> staged unstaged path
\r
326 1: binary nothing foo.png
\r
327 2: +403/-35 +1/-1 git-add--interactive.perl</screen>
\r
328 <simpara>It shows that foo.png has differences from HEAD (but that is
\r
329 binary so line count cannot be shown) and there is no
\r
330 difference between indexed copy and the working tree
\r
331 version (if the working tree version were also different,
\r
332 <emphasis>binary</emphasis> would have been shown in place of <emphasis>nothing</emphasis>). The
\r
333 other file, git-add--interactive.perl, has 403 lines added
\r
334 and 35 lines deleted if you commit what is in the index, but
\r
335 working tree file has further modifications (one addition and
\r
336 one deletion).</simpara>
\r
345 This shows the status information and issues an "Update>>"
\r
346 prompt. When the prompt ends with double <emphasis>>></emphasis>, you can
\r
347 make more than one selection, concatenated with whitespace or
\r
348 comma. Also you can say ranges. E.g. "2-5 7,9" to choose
\r
349 2,3,4,5,7,9 from the list. If the second number in a range is
\r
350 omitted, all remaining patches are taken. E.g. "7-" to choose
\r
351 7,8,9 from the list. You can say <emphasis>*</emphasis> to choose everything.
\r
353 <simpara>What you chose are then highlighted with <emphasis>*</emphasis>,
\r
354 like this:</simpara>
\r
355 <screen> staged unstaged path
\r
356 1: binary nothing foo.png
\r
357 * 2: +403/-35 +1/-1 git-add--interactive.perl</screen>
\r
358 <simpara>To remove selection, prefix the input with <emphasis>-</emphasis>
\r
359 like this:</simpara>
\r
360 <screen>Update>> -2</screen>
\r
361 <simpara>After making the selection, answer with an empty line to stage the
\r
362 contents of working tree files for selected paths in the index.</simpara>
\r
371 This has a very similar UI to <emphasis>update</emphasis>, and the staged
\r
372 information for selected paths are reverted to that of the
\r
373 HEAD version. Reverting new paths makes them untracked.
\r
383 This has a very similar UI to <emphasis>update</emphasis> and
\r
384 <emphasis>revert</emphasis>, and lets you add untracked paths to the index.
\r
394 This lets you choose one path out of a <emphasis>status</emphasis> like selection.
\r
395 After choosing the path, it presents the diff between the index
\r
396 and the working tree file and asks you if you want to stage
\r
397 the change of each hunk. You can select one of the following
\r
398 options and type return:
\r
400 <literallayout class="monospaced">y - stage this hunk
\r
401 n - do not stage this hunk
\r
402 q - quit; do not stage this hunk nor any of the remaining ones
\r
403 a - stage this hunk and all later hunks in the file
\r
404 d - do not stage this hunk nor any of the later hunks in the file
\r
405 g - select a hunk to go to
\r
406 / - search for a hunk matching the given regex
\r
407 j - leave this hunk undecided, see next undecided hunk
\r
408 J - leave this hunk undecided, see next hunk
\r
409 k - leave this hunk undecided, see previous undecided hunk
\r
410 K - leave this hunk undecided, see previous hunk
\r
411 s - split the current hunk into smaller hunks
\r
412 e - manually edit the current hunk
\r
413 ? - print help</literallayout>
\r
414 <simpara>After deciding the fate for all hunks, if there is any hunk
\r
415 that was chosen, the index is updated with the selected hunks.</simpara>
\r
416 <simpara>You can omit having to type return here, by setting the configuration
\r
417 variable <emphasis>interactive.singlekey</emphasis> to <emphasis>true</emphasis>.</simpara>
\r
426 This lets you review what will be committed (i.e. between
\r
433 <simplesect id="git-add(1)__editing_patches">
\r
434 <title>EDITING PATCHES</title>
\r
435 <simpara>Invoking <emphasis>git add -e</emphasis> or selecting <emphasis>e</emphasis> from the interactive hunk
\r
436 selector will open a patch in your editor; after the editor exits, the
\r
437 result is applied to the index. You are free to make arbitrary changes
\r
438 to the patch, but note that some changes may have confusing results, or
\r
439 even result in a patch that cannot be applied. If you want to abort the
\r
440 operation entirely (i.e., stage nothing new in the index), simply delete
\r
441 all lines of the patch. The list below describes some common things you
\r
442 may see in a patch, and which editing operations make sense on them.</simpara>
\r
450 Added content is represented by lines beginning with "+". You can
\r
451 prevent staging any addition lines by deleting them.
\r
461 Removed content is represented by lines beginning with "-". You can
\r
462 prevent staging their removal by converting the "-" to a " " (space).
\r
472 Modified content is represented by "-" lines (removing the old content)
\r
473 followed by "+" lines (adding the replacement content). You can
\r
474 prevent staging the modification by converting "-" lines to " ", and
\r
475 removing "+" lines. Beware that modifying only half of the pair is
\r
476 likely to introduce confusing changes to the index.
\r
481 <simpara>There are also more complex operations that can be performed. But beware
\r
482 that because the patch is applied only to the index and not the working
\r
483 tree, the working tree will appear to "undo" the change in the index.
\r
484 For example, introducing a new line into the index that is in neither
\r
485 the HEAD nor the working tree will stage the new line for commit, but
\r
486 the line will appear to be reverted in the working tree.</simpara>
\r
487 <simpara>Avoid using these constructs, or do so with extreme caution.</simpara>
\r
491 removing untouched content
\r
495 Content which does not differ between the index and working tree may be
\r
496 shown on context lines, beginning with a " " (space). You can stage
\r
497 context lines for removal by converting the space to a "-". The
\r
498 resulting working tree file will appear to re-add the content.
\r
504 modifying existing content
\r
508 One can also modify context lines by staging them for removal (by
\r
509 converting " " to "-") and adding a "+" line with the new content.
\r
510 Similarly, one can modify "+" lines for existing additions or
\r
511 modifications. In all cases, the new modification will appear reverted
\r
512 in the working tree.
\r
522 You may also add new content that does not exist in the patch; simply
\r
523 add new lines, each starting with "+". The addition will appear
\r
524 reverted in the working tree.
\r
529 <simpara>There are also several operations which should be avoided entirely, as
\r
530 they will make the patch impossible to apply:</simpara>
\r
534 adding context (" ") or removal ("-") lines
\r
539 deleting context or removal lines
\r
544 modifying the contents of context or removal lines
\r
549 <simplesect id="git-add(1)__see_also">
\r
550 <title>SEE ALSO</title>
\r
551 <simpara><xref linkend="git-status(1)" />
\r
552 <xref linkend="git-rm(1)" />
\r
553 <xref linkend="git-reset(1)" />
\r
554 <xref linkend="git-mv(1)" />
\r
555 <xref linkend="git-commit(1)" />
\r
556 <xref linkend="git-update-index(1)" /></simpara>
\r
558 <simplesect id="git-add(1)__git">
\r
560 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
\r