1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <!DOCTYPE sect2 SYSTEM "../../../dtd/dblite.dtd">
\r
4 <sect2 lang="en" id="git-add(1)">
\r
5 <title>git-add(1)</title>
\r
6 <date>2024-07-02</date>
\r
7 <revhistory><revision><date>2024-07-02</date></revision></revhistory>
\r
9 <primary>git-add(1)</primary>
\r
11 <simplesect id="git-add(1)__name">
\r
13 <simpara>git-add - Add file contents to the index</simpara>
\r
15 <simplesect id="git-add(1)__synopsis">
\r
16 <title>SYNOPSIS</title>
\r
18 <literallayout><emphasis>git add</emphasis> [--verbose | -v] [--dry-run | -n] [--force | -f] [--interactive | -i] [--patch | -p]
\r
19 [--edit | -e] [--[no-]all | -A | --[no-]ignore-removal | [--update | -u]] [--sparse]
\r
20 [--intent-to-add | -N] [--refresh] [--ignore-errors] [--ignore-missing] [--renormalize]
\r
21 [--chmod=(+|-)x] [--pathspec-from-file=<file> [--pathspec-file-nul]]
\r
22 [--] [<pathspec>…]</literallayout>
\r
25 <simplesect id="git-add(1)__description">
\r
26 <title>DESCRIPTION</title>
\r
27 <simpara>This command updates the index using the current content found in
\r
28 the working tree, to prepare the content staged for the next commit.
\r
29 It typically adds the current content of existing paths as a whole,
\r
30 but with some options it can also be used to add content with
\r
31 only part of the changes made to the working tree files applied, or
\r
32 remove paths that do not exist in the working tree anymore.</simpara>
\r
33 <simpara>The "index" holds a snapshot of the content of the working tree, and it
\r
34 is this snapshot that is taken as the contents of the next commit. Thus
\r
35 after making any changes to the working tree, and before running
\r
36 the commit command, you must use the <emphasis>add</emphasis> command to add any new or
\r
37 modified files to the index.</simpara>
\r
38 <simpara>This command can be performed multiple times before a commit. It only
\r
39 adds the content of the specified file(s) at the time the add command is
\r
40 run; if you want subsequent changes included in the next commit, then
\r
41 you must run <emphasis>git add</emphasis> again to add the new content to the index.</simpara>
\r
42 <simpara>The <emphasis>git status</emphasis> command can be used to obtain a summary of which
\r
43 files have changes that are staged for the next commit.</simpara>
\r
44 <simpara>The <emphasis>git add</emphasis> command will not add ignored files by default. If any
\r
45 ignored files were explicitly specified on the command line, <emphasis>git add</emphasis>
\r
46 will fail with a list of ignored files. Ignored files reached by
\r
47 directory recursion or filename globbing performed by Git (quote your
\r
48 globs before the shell) will be silently ignored. The <emphasis>git add</emphasis> command can
\r
49 be used to add ignored files with the <emphasis>-f</emphasis> (force) option.</simpara>
\r
50 <simpara>Please see <xref linkend="git-commit(1)" /> for alternative ways to add content to a
\r
53 <simplesect id="git-add(1)__options">
\r
54 <title>OPTIONS</title>
\r
58 <pathspec>…
\r
62 Files to add content from. Fileglobs (e.g. <emphasis>*.c</emphasis>) can
\r
63 be given to add all matching files. Also a
\r
64 leading directory name (e.g. <emphasis>dir</emphasis> to add <emphasis>dir/file1</emphasis>
\r
65 and <emphasis>dir/file2</emphasis>) can be given to update the index to
\r
66 match the current state of the directory as a whole (e.g.
\r
67 specifying <emphasis>dir</emphasis> will record not just a file <emphasis>dir/file1</emphasis>
\r
68 modified in the working tree, a file <emphasis>dir/file2</emphasis> added to
\r
69 the working tree, but also a file <emphasis>dir/file3</emphasis> removed from
\r
70 the working tree). Note that older versions of Git used
\r
71 to ignore removed files; use <emphasis>--no-all</emphasis> option if you want
\r
72 to add modified or new files but ignore removed ones.
\r
74 <simpara>For more details about the <emphasis><pathspec></emphasis> syntax, see the <emphasis>pathspec</emphasis> entry
\r
75 in <xref linkend="gitglossary(7)" />.</simpara>
\r
87 Don't actually add the file(s), just show if they exist and/or will
\r
114 Allow adding otherwise ignored files.
\r
124 Allow updating index entries outside of the sparse-checkout cone.
\r
125 Normally, <emphasis>git add</emphasis> refuses to update index entries whose paths do
\r
126 not fit within the sparse-checkout cone, since those files might
\r
127 be removed from the working tree without warning. See
\r
128 <xref linkend="git-sparse-checkout(1)" /> for more details.
\r
141 Add modified contents in the working tree interactively to
\r
142 the index. Optional path arguments may be supplied to limit
\r
143 operation to a subset of the working tree. See Interactive
\r
157 Interactively choose hunks of patch between the index and the
\r
158 work tree and add them to the index. This gives the user a chance
\r
159 to review the difference before adding modified contents to the
\r
162 <simpara>This effectively runs <emphasis>add --interactive</emphasis>, but bypasses the
\r
163 initial command menu and directly jumps to the <emphasis>patch</emphasis> subcommand.
\r
164 See Interactive mode for details.</simpara>
\r
176 Open the diff vs. the index in an editor and let the user
\r
177 edit it. After the editor was closed, adjust the hunk headers
\r
178 and apply the patch to the index.
\r
180 <simpara>The intent of this option is to pick and choose lines of the patch to
\r
181 apply, or even to modify the contents of lines to be staged. This can be
\r
182 quicker and more flexible than using the interactive hunk selector.
\r
183 However, it is easy to confuse oneself and create a patch that does not
\r
184 apply to the index. See EDITING PATCHES below.</simpara>
\r
196 Update the index just where it already has an entry matching
\r
197 <emphasis><pathspec></emphasis>. This removes as well as modifies index entries to
\r
198 match the working tree, but adds no new files.
\r
200 <simpara>If no <emphasis><pathspec></emphasis> is given when <emphasis>-u</emphasis> option is used, all
\r
201 tracked files in the entire working tree are updated (old versions
\r
202 of Git used to limit the update to the current directory and its
\r
203 subdirectories).</simpara>
\r
214 --no-ignore-removal
\r
218 Update the index not only where the working tree has a file
\r
219 matching <emphasis><pathspec></emphasis> but also where the index already has an
\r
220 entry. This adds, modifies, and removes index entries to
\r
221 match the working tree.
\r
223 <simpara>If no <emphasis><pathspec></emphasis> is given when <emphasis>-A</emphasis> option is used, all
\r
224 files in the entire working tree are updated (old versions
\r
225 of Git used to limit the update to the current directory and its
\r
226 subdirectories).</simpara>
\r
238 Update the index by adding new files that are unknown to the
\r
239 index and files modified in the working tree, but ignore
\r
240 files that have been removed from the working tree. This
\r
241 option is a no-op when no <emphasis><pathspec></emphasis> is used.
\r
243 <simpara>This option is primarily to help users who are used to older
\r
244 versions of Git, whose "git add <emphasis><pathspec></emphasis>…" was a synonym
\r
245 for "git add --no-all <emphasis><pathspec></emphasis>…", i.e. ignored removed files.</simpara>
\r
257 Record only the fact that the path will be added later. An entry
\r
258 for the path is placed in the index with no content. This is
\r
259 useful for, among other things, showing the unstaged content of
\r
260 such files with <emphasis>git diff</emphasis> and committing them with <emphasis>git commit
\r
271 Don't add the file(s), but only refresh their stat()
\r
272 information in the index.
\r
282 If some files could not be added because of errors indexing
\r
283 them, do not abort the operation, but continue adding the
\r
284 others. The command shall still exit with non-zero status.
\r
285 The configuration variable <emphasis>add.ignoreErrors</emphasis> can be set to
\r
286 true to make this the default behaviour.
\r
296 This option can only be used together with --dry-run. By using
\r
297 this option the user can check if any of the given files would
\r
298 be ignored, no matter if they are already present in the work
\r
305 --no-warn-embedded-repo
\r
309 By default, <emphasis>git add</emphasis> will warn when adding an embedded
\r
310 repository to the index without using <emphasis>git submodule add</emphasis> to
\r
311 create an entry in <emphasis>.gitmodules</emphasis>. This option will suppress the
\r
312 warning (e.g., if you are manually performing operations on
\r
323 Apply the "clean" process freshly to all tracked files to
\r
324 forcibly add them again to the index. This is useful after
\r
325 changing <emphasis>core.autocrlf</emphasis> configuration or the <emphasis>text</emphasis> attribute
\r
326 in order to correct files added with wrong CRLF/LF line endings.
\r
327 This option implies <emphasis>-u</emphasis>. Lone CR characters are untouched, thus
\r
328 while a CRLF cleans to LF, a CRCRLF sequence is only partially
\r
339 Override the executable bit of the added files. The executable
\r
340 bit is only changed in the index, the files on disk are left
\r
347 --pathspec-from-file=<file>
\r
351 Pathspec is passed in <emphasis><file></emphasis> instead of commandline args. If
\r
352 <emphasis><file></emphasis> is exactly <emphasis>-</emphasis> then standard input is used. Pathspec
\r
353 elements are separated by LF or CR/LF. Pathspec elements can be
\r
354 quoted as explained for the configuration variable <emphasis>core.quotePath</emphasis>
\r
355 (see <xref linkend="git-config(1)" />). See also <emphasis>--pathspec-file-nul</emphasis> and
\r
356 global <emphasis>--literal-pathspecs</emphasis>.
\r
362 --pathspec-file-nul
\r
366 Only meaningful with <emphasis>--pathspec-from-file</emphasis>. Pathspec elements are
\r
367 separated with NUL character and all other characters are taken
\r
368 literally (including newlines and quotes).
\r
378 This option can be used to separate command-line options from
\r
379 the list of files, (useful when filenames might be mistaken
\r
380 for command-line options).
\r
386 <simplesect id="git-add(1)__examples">
\r
387 <title>EXAMPLES</title>
\r
391 Adds content from all <emphasis>*.txt</emphasis> files under <emphasis>Documentation</emphasis> directory
\r
392 and its subdirectories:
\r
394 <screen>$ git add Documentation/\*.txt</screen>
\r
395 <simpara>Note that the asterisk <emphasis>*</emphasis> is quoted from the shell in this
\r
396 example; this lets the command include the files from
\r
397 subdirectories of <emphasis>Documentation/</emphasis> directory.</simpara>
\r
401 Considers adding content from all git-*.sh scripts:
\r
403 <screen>$ git add git-*.sh</screen>
\r
404 <simpara>Because this example lets the shell expand the asterisk (i.e. you are
\r
405 listing the files explicitly), it does not consider
\r
406 <emphasis>subdir/git-foo.sh</emphasis>.</simpara>
\r
410 <simplesect id="git-add(1)__interactive_mode">
\r
411 <title>INTERACTIVE MODE</title>
\r
412 <simpara>When the command enters the interactive mode, it shows the
\r
413 output of the <emphasis>status</emphasis> subcommand, and then goes into its
\r
414 interactive command loop.</simpara>
\r
415 <simpara>The command loop shows the list of subcommands available, and
\r
416 gives a prompt "What now> ". In general, when the prompt ends
\r
417 with a single <emphasis>></emphasis>, you can pick only one of the choices given
\r
418 and type return, like this:</simpara>
\r
419 <screen> *** Commands ***
\r
420 1: status 2: update 3: revert 4: add untracked
\r
421 5: patch 6: diff 7: quit 8: help
\r
422 What now> 1</screen>
\r
423 <simpara>You also could say <emphasis>s</emphasis> or <emphasis>sta</emphasis> or <emphasis>status</emphasis> above as long as the
\r
424 choice is unique.</simpara>
\r
425 <simpara>The main command loop has 6 subcommands (plus help and quit).</simpara>
\r
433 This shows the change between HEAD and index (i.e. what will be
\r
434 committed if you say <emphasis>git commit</emphasis>), and between index and
\r
435 working tree files (i.e. what you could stage further before
\r
436 <emphasis>git commit</emphasis> using <emphasis>git add</emphasis>) for each path. A sample output
\r
439 <screen> staged unstaged path
\r
440 1: binary nothing foo.png
\r
441 2: +403/-35 +1/-1 add-interactive.c</screen>
\r
442 <simpara>It shows that foo.png has differences from HEAD (but that is
\r
443 binary so line count cannot be shown) and there is no
\r
444 difference between indexed copy and the working tree
\r
445 version (if the working tree version were also different,
\r
446 <emphasis>binary</emphasis> would have been shown in place of <emphasis>nothing</emphasis>). The
\r
447 other file, add-interactive.c, has 403 lines added
\r
448 and 35 lines deleted if you commit what is in the index, but
\r
449 working tree file has further modifications (one addition and
\r
450 one deletion).</simpara>
\r
459 This shows the status information and issues an "Update>>"
\r
460 prompt. When the prompt ends with double <emphasis>>></emphasis>, you can
\r
461 make more than one selection, concatenated with whitespace or
\r
462 comma. Also you can say ranges. E.g. "2-5 7,9" to choose
\r
463 2,3,4,5,7,9 from the list. If the second number in a range is
\r
464 omitted, all remaining patches are taken. E.g. "7-" to choose
\r
465 7,8,9 from the list. You can say <emphasis>*</emphasis> to choose everything.
\r
467 <simpara>What you chose are then highlighted with <emphasis>*</emphasis>,
\r
468 like this:</simpara>
\r
469 <screen> staged unstaged path
\r
470 1: binary nothing foo.png
\r
471 * 2: +403/-35 +1/-1 add-interactive.c</screen>
\r
472 <simpara>To remove selection, prefix the input with <emphasis>-</emphasis>
\r
473 like this:</simpara>
\r
474 <screen>Update>> -2</screen>
\r
475 <simpara>After making the selection, answer with an empty line to stage the
\r
476 contents of working tree files for selected paths in the index.</simpara>
\r
485 This has a very similar UI to <emphasis>update</emphasis>, and the staged
\r
486 information for selected paths are reverted to that of the
\r
487 HEAD version. Reverting new paths makes them untracked.
\r
497 This has a very similar UI to <emphasis>update</emphasis> and
\r
498 <emphasis>revert</emphasis>, and lets you add untracked paths to the index.
\r
508 This lets you choose one path out of a <emphasis>status</emphasis> like selection.
\r
509 After choosing the path, it presents the diff between the index
\r
510 and the working tree file and asks you if you want to stage
\r
511 the change of each hunk. You can select one of the following
\r
512 options and type return:
\r
514 <literallayout class="monospaced">y - stage this hunk
\r
515 n - do not stage this hunk
\r
516 q - quit; do not stage this hunk or any of the remaining ones
\r
517 a - stage this hunk and all later hunks in the file
\r
518 d - do not stage this hunk or any of the later hunks in the file
\r
519 g - select a hunk to go to
\r
520 / - search for a hunk matching the given regex
\r
521 j - leave this hunk undecided, see next undecided hunk
\r
522 J - leave this hunk undecided, see next hunk
\r
523 k - leave this hunk undecided, see previous undecided hunk
\r
524 K - leave this hunk undecided, see previous hunk
\r
525 s - split the current hunk into smaller hunks
\r
526 e - manually edit the current hunk
\r
527 p - print the current hunk
\r
528 ? - print help</literallayout>
\r
529 <simpara>After deciding the fate for all hunks, if there is any hunk
\r
530 that was chosen, the index is updated with the selected hunks.</simpara>
\r
531 <simpara>You can omit having to type return here, by setting the configuration
\r
532 variable <emphasis>interactive.singleKey</emphasis> to <emphasis>true</emphasis>.</simpara>
\r
541 This lets you review what will be committed (i.e. between
\r
548 <simplesect id="git-add(1)__editing_patches">
\r
549 <title>EDITING PATCHES</title>
\r
550 <simpara>Invoking <emphasis>git add -e</emphasis> or selecting <emphasis>e</emphasis> from the interactive hunk
\r
551 selector will open a patch in your editor; after the editor exits, the
\r
552 result is applied to the index. You are free to make arbitrary changes
\r
553 to the patch, but note that some changes may have confusing results, or
\r
554 even result in a patch that cannot be applied. If you want to abort the
\r
555 operation entirely (i.e., stage nothing new in the index), simply delete
\r
556 all lines of the patch. The list below describes some common things you
\r
557 may see in a patch, and which editing operations make sense on them.</simpara>
\r
565 Added content is represented by lines beginning with "+". You can
\r
566 prevent staging any addition lines by deleting them.
\r
576 Removed content is represented by lines beginning with "-". You can
\r
577 prevent staging their removal by converting the "-" to a " " (space).
\r
587 Modified content is represented by "-" lines (removing the old content)
\r
588 followed by "+" lines (adding the replacement content). You can
\r
589 prevent staging the modification by converting "-" lines to " ", and
\r
590 removing "+" lines. Beware that modifying only half of the pair is
\r
591 likely to introduce confusing changes to the index.
\r
596 <simpara>There are also more complex operations that can be performed. But beware
\r
597 that because the patch is applied only to the index and not the working
\r
598 tree, the working tree will appear to "undo" the change in the index.
\r
599 For example, introducing a new line into the index that is in neither
\r
600 the HEAD nor the working tree will stage the new line for commit, but
\r
601 the line will appear to be reverted in the working tree.</simpara>
\r
602 <simpara>Avoid using these constructs, or do so with extreme caution.</simpara>
\r
606 removing untouched content
\r
610 Content which does not differ between the index and working tree may be
\r
611 shown on context lines, beginning with a " " (space). You can stage
\r
612 context lines for removal by converting the space to a "-". The
\r
613 resulting working tree file will appear to re-add the content.
\r
619 modifying existing content
\r
623 One can also modify context lines by staging them for removal (by
\r
624 converting " " to "-") and adding a "+" line with the new content.
\r
625 Similarly, one can modify "+" lines for existing additions or
\r
626 modifications. In all cases, the new modification will appear reverted
\r
627 in the working tree.
\r
637 You may also add new content that does not exist in the patch; simply
\r
638 add new lines, each starting with "+". The addition will appear
\r
639 reverted in the working tree.
\r
644 <simpara>There are also several operations which should be avoided entirely, as
\r
645 they will make the patch impossible to apply:</simpara>
\r
649 adding context (" ") or removal ("-") lines
\r
654 deleting context or removal lines
\r
659 modifying the contents of context or removal lines
\r
664 <simplesect id="git-add(1)__configuration">
\r
665 <title>CONFIGURATION</title>
\r
666 <simpara>Everything below this line in this section is selectively included
\r
667 from the <xref linkend="git-config(1)" /> documentation. The content is the same
\r
668 as what's found there:</simpara>
\r
675 add.ignore-errors (deprecated)
\r
679 Tells <emphasis>git add</emphasis> to continue adding files when some files cannot be
\r
680 added due to indexing errors. Equivalent to the <emphasis>--ignore-errors</emphasis>
\r
681 option of <xref linkend="git-add(1)" />. <emphasis>add.ignore-errors</emphasis> is deprecated,
\r
682 as it does not follow the usual naming convention for configuration
\r
689 add.interactive.useBuiltin
\r
693 Unused configuration variable. Used in Git versions v2.25.0 to
\r
694 v2.36.0 to enable the built-in version of <xref linkend="git-add(1)" />'s
\r
695 interactive mode, which then became the default in Git
\r
696 versions v2.37.0 to v2.39.0.
\r
702 <simplesect id="git-add(1)__see_also">
\r
703 <title>SEE ALSO</title>
\r
704 <simpara><xref linkend="git-status(1)" />
\r
705 <xref linkend="git-rm(1)" />
\r
706 <xref linkend="git-reset(1)" />
\r
707 <xref linkend="git-mv(1)" />
\r
708 <xref linkend="git-commit(1)" />
\r
709 <xref linkend="git-update-index(1)" /></simpara>
\r
711 <simplesect id="git-add(1)__git">
\r
713 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
\r