1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml" xml:
lang=
"en">
5 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8" />
6 <meta name=
"generator" content=
"AsciiDoc 8.4.5" />
7 <title>git-add(
1)
</title>
8 <style type=
"text/css">
10 p
, li
, dt
, dd
, div
, pre
, h1
, h2
, h3
, h4
, h5
, h6
{
12 border: 1px solid red;
17 margin: 1em 5% 1em 5%;
22 text-decoration: underline
;
42 h1
, h2
, h3
, h4
, h5
, h6
{
44 font-family: sans-serif
;
51 border-bottom: 2px solid silver
;
69 border: 1px solid silver
;
88 font-family: sans-serif
;
94 span#revnumber
, span#revdate
, span#revremark
{
95 font-family: sans-serif
;
99 font-family: sans-serif
;
101 border-top: 2px solid silver
;
107 padding-bottom: 0.5em;
111 padding-bottom: 0.5em;
116 margin-bottom: 1.5em;
118 div
.tableblock
, div
.imageblock
, div
.exampleblock
, div
.verseblock
,
119 div
.quoteblock
, div
.literalblock
, div
.listingblock
, div
.sidebarblock
,
120 div
.admonitionblock
{
122 margin-bottom: 1.5em;
124 div
.admonitionblock
{
126 margin-bottom: 2.5em;
129 div
.content
{ /* Block element content. */
133 /* Block element titles. */
134 div
.title
, caption
.title
{
136 font-family: sans-serif
;
140 margin-bottom: 0.5em;
146 td div
.title:first-child
{
149 div
.content div
.title:first-child
{
152 div
.content
+ div
.title
{
156 div
.sidebarblock
> div
.content
{
158 border: 1px solid silver
;
162 div
.listingblock
> div
.content
{
163 border: 1px solid silver
;
172 div
.quoteblock
> div
.attribution
{
181 div
.verseblock
> div
.content
{
184 div
.verseblock
> div
.attribution
{
188 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
189 div
.verseblock
+ div
.attribution
{
193 div
.admonitionblock
.icon
{
197 text-decoration: underline
;
199 padding-right: 0.5em;
201 div
.admonitionblock td
.content
{
203 border-left: 2px solid silver
;
206 div
.exampleblock
> div
.content
{
207 border-left: 2px solid silver
;
211 div
.imageblock div
.content
{ padding-left: 0; }
212 span
.image img
{ border-style: none
; }
213 a
.image:visited
{ color: white
; }
217 margin-bottom: 0.8em;
230 list-style-position: outside
;
233 list-style-type: decimal
;
236 list-style-type: lower-alpha
;
239 list-style-type: upper-alpha
;
242 list-style-type: lower-roman
;
245 list-style-type: upper-roman
;
248 div
.compact ul
, div
.compact ol
,
249 div
.compact p
, div
.compact p
,
250 div
.compact div
, div
.compact div
{
252 margin-bottom: 0.1em;
255 div
.tableblock
> table
{
256 border: 3px solid
#527bbd;
259 font-family: sans-serif
;
271 /* Because the table frame attribute is overriden by CSS in most browsers. */
272 div
.tableblock
> table
[frame
="void"] {
275 div
.tableblock
> table
[frame
="hsides"] {
276 border-left-style: none
;
277 border-right-style: none
;
279 div
.tableblock
> table
[frame
="vsides"] {
280 border-top-style: none
;
281 border-bottom-style: none
;
287 margin-bottom: 0.8em;
290 padding-bottom: 15px;
292 dt
.hdlist1
.strong
, td
.hdlist1
.strong
{
298 padding-right: 0.8em;
304 div
.hdlist
.compact tr
{
314 div#footer-badges
{ display: none
; }
319 font-family: sans-serif
;
323 margin-bottom: 0.1em;
326 div
.toclevel1
, div
.toclevel2
, div
.toclevel3
, div
.toclevel4
{
342 /* Overrides for manpage documents */
345 padding-bottom: 0.5em;
346 border-top: 2px solid silver
;
347 border-bottom: 2px solid silver
;
357 div#toc
{ display: none
; }
360 /* Workarounds for IE6's broken and incomplete CSS2. */
362 div
.sidebar-content
{
364 border: 1px solid silver
;
367 div
.sidebar-title
, div
.image-title
{
369 font-family: sans-serif
;
372 margin-bottom: 0.5em;
375 div
.listingblock div
.content
{
376 border: 1px solid silver
;
381 div
.quoteblock-attribution
{
386 div
.verseblock-content
{
389 div
.verseblock-attribution
{
394 div
.exampleblock-content
{
395 border-left: 2px solid silver
;
399 /* IE6 sets dynamically generated links as visited. */
400 div#toc
a:visited
{ color: blue
; }
406 git-add(
1) Manual Page
409 <div class=
"sectionbody">
411 Add file contents to the index
415 <h2 id=
"_synopsis">SYNOPSIS
</h2>
416 <div class=
"sectionbody">
417 <div class=
"verseblock">
418 <div class=
"verseblock-content"><em>git add
</em> [-n] [-v] [--force | -f] [--interactive | -i] [--patch | -p]
419 [--edit | -e] [--all | [--update | -u]] [--intent-to-add | -N]
420 [--refresh] [--ignore-errors] [--ignore-missing] [--]
421 [
<filepattern
>…]
</div>
422 <div class=
"verseblock-attribution">
425 <h2 id=
"_description">DESCRIPTION
</h2>
426 <div class=
"sectionbody">
427 <div class=
"paragraph"><p>This command updates the index using the current content found in
428 the working tree, to prepare the content staged for the next commit.
429 It typically adds the current content of existing paths as a whole,
430 but with some options it can also be used to add content with
431 only part of the changes made to the working tree files applied, or
432 remove paths that do not exist in the working tree anymore.
</p></div>
433 <div class=
"paragraph"><p>The
"index" holds a snapshot of the content of the working tree, and it
434 is this snapshot that is taken as the contents of the next commit. Thus
435 after making any changes to the working directory, and before running
436 the commit command, you must use the
<tt>add
</tt> command to add any new or
437 modified files to the index.
</p></div>
438 <div class=
"paragraph"><p>This command can be performed multiple times before a commit. It only
439 adds the content of the specified file(s) at the time the add command is
440 run; if you want subsequent changes included in the next commit, then
441 you must run
<tt>git add
</tt> again to add the new content to the index.
</p></div>
442 <div class=
"paragraph"><p>The
<tt>git status
</tt> command can be used to obtain a summary of which
443 files have changes that are staged for the next commit.
</p></div>
444 <div class=
"paragraph"><p>The
<tt>git add
</tt> command will not add ignored files by default. If any
445 ignored files were explicitly specified on the command line,
<tt>git add
</tt>
446 will fail with a list of ignored files. Ignored files reached by
447 directory recursion or filename globbing performed by Git (quote your
448 globs before the shell) will be silently ignored. The
<em>git add
</em> command can
449 be used to add ignored files with the
<tt>-f
</tt> (force) option.
</p></div>
450 <div class=
"paragraph"><p>Please see
<a href=
"git-commit.html">git-commit(
1)
</a> for alternative ways to add content to a
453 <h2 id=
"_options">OPTIONS
</h2>
454 <div class=
"sectionbody">
455 <div class=
"dlist"><dl>
457 <filepattern
>…
461 Files to add content from. Fileglobs (e.g.
<tt>*.c
</tt>) can
462 be given to add all matching files. Also a
463 leading directory name (e.g.
<tt>dir
</tt> to add
<tt>dir/file1
</tt>
464 and
<tt>dir/file2
</tt>) can be given to add all files in the
465 directory, recursively.
476 Don
’t actually add the file(s), just show if they exist and/or will
499 Allow adding otherwise ignored files.
510 Add modified contents in the working tree interactively to
511 the index. Optional path arguments may be supplied to limit
512 operation to a subset of the working tree. See
“Interactive
513 mode
” for details.
524 Interactively choose hunks of patch between the index and the
525 work tree and add them to the index. This gives the user a chance
526 to review the difference before adding modified contents to the
529 <div class=
"paragraph"><p>This effectively runs
<tt>add --interactive
</tt>, but bypasses the
530 initial command menu and directly jumps to the
<tt>patch
</tt> subcommand.
531 See
“Interactive mode
” for details.
</p></div>
538 Open the diff vs. the index in an editor and let the user
539 edit it. After the editor was closed, adjust the hunk headers
540 and apply the patch to the index.
542 <div class=
"paragraph"><p>The intent of this option is to pick and choose lines of the patch to
543 apply, or even to modify the contents of lines to be staged. This can be
544 quicker and more flexible than using the interactive hunk selector.
545 However, it is easy to confuse oneself and create a patch that does not
546 apply to the index. See EDITING PATCHES below.
</p></div>
556 Only match
<filepattern
> against already tracked files in
557 the index rather than the working tree. That means that it
558 will never stage new files, but that it will stage modified
559 new contents of tracked files and that it will remove files
560 from the index if the corresponding files in the working tree
563 <div class=
"paragraph"><p>If no
<filepattern
> is given, default to
"."; in other words,
564 update all tracked files in the current directory and its
565 subdirectories.
</p></div>
575 Like
<tt>-u
</tt>, but match
<filepattern
> against files in the
576 working tree in addition to the index. That means that it
577 will find new files as well as staging modified content and
578 removing files that are no longer in the working tree.
589 Record only the fact that the path will be added later. An entry
590 for the path is placed in the index with no content. This is
591 useful for, among other things, showing the unstaged content of
592 such files with
<tt>git diff
</tt> and committing them with
<tt>git commit
601 Don
’t add the file(s), but only refresh their stat()
602 information in the index.
610 If some files could not be added because of errors indexing
611 them, do not abort the operation, but continue adding the
612 others. The command shall still exit with non-zero status.
613 The configuration variable
<tt>add.ignoreErrors
</tt> can be set to
614 true to make this the default behaviour.
622 This option can only be used together with --dry-run. By using
623 this option the user can check if any of the given files would
624 be ignored, no matter if they are already present in the work
633 This option can be used to separate command-line options from
634 the list of files, (useful when filenames might be mistaken
635 for command-line options).
640 <h2 id=
"_configuration">Configuration
</h2>
641 <div class=
"sectionbody">
642 <div class=
"paragraph"><p>The optional configuration variable
<tt>core.excludesfile
</tt> indicates a path to a
643 file containing patterns of file names to exclude from git-add, similar to
644 $GIT_DIR/info/exclude. Patterns in the exclude file are used in addition to
645 those in info/exclude. See
<a href=
"gitrepository-layout.html">gitrepository-layout(
5)
</a>.
</p></div>
647 <h2 id=
"_examples">EXAMPLES
</h2>
648 <div class=
"sectionbody">
649 <div class=
"ulist"><ul>
652 Adds content from all
<tt>*.txt
</tt> files under
<tt>Documentation
</tt> directory
653 and its subdirectories:
655 <div class=
"listingblock">
656 <div class=
"content">
657 <pre><tt>$ git add Documentation/\*.txt
</tt></pre>
659 <div class=
"paragraph"><p>Note that the asterisk
<tt>*
</tt> is quoted from the shell in this
660 example; this lets the command include the files from
661 subdirectories of
<tt>Documentation/
</tt> directory.
</p></div>
665 Considers adding content from all git-*.sh scripts:
667 <div class=
"listingblock">
668 <div class=
"content">
669 <pre><tt>$ git add git-*.sh
</tt></pre>
671 <div class=
"paragraph"><p>Because this example lets the shell expand the asterisk (i.e. you are
672 listing the files explicitly), it does not consider
673 <tt>subdir/git-foo.sh
</tt>.
</p></div>
677 <h2 id=
"_interactive_mode">Interactive mode
</h2>
678 <div class=
"sectionbody">
679 <div class=
"paragraph"><p>When the command enters the interactive mode, it shows the
680 output of the
<em>status
</em> subcommand, and then goes into its
681 interactive command loop.
</p></div>
682 <div class=
"paragraph"><p>The command loop shows the list of subcommands available, and
683 gives a prompt
"What now> ". In general, when the prompt ends
684 with a single
<em>></em>, you can pick only one of the choices given
685 and type return, like this:
</p></div>
686 <div class=
"listingblock">
687 <div class=
"content">
688 <pre><tt> *** Commands ***
689 1: status
2: update
3: revert
4: add untracked
690 5: patch
6: diff
7: quit
8: help
691 What now
> 1</tt></pre>
693 <div class=
"paragraph"><p>You also could say
<tt>s
</tt> or
<tt>sta
</tt> or
<tt>status
</tt> above as long as the
694 choice is unique.
</p></div>
695 <div class=
"paragraph"><p>The main command loop has
6 subcommands (plus help and quit).
</p></div>
696 <div class=
"dlist"><dl>
702 This shows the change between HEAD and index (i.e. what will be
703 committed if you say
<tt>git commit
</tt>), and between index and
704 working tree files (i.e. what you could stage further before
705 <tt>git commit
</tt> using
<tt>git add
</tt>) for each path. A sample output
708 <div class=
"listingblock">
709 <div class=
"content">
710 <pre><tt> staged unstaged path
711 1: binary nothing foo.png
712 2: +
403/-
35 +
1/-
1 git-add--interactive.perl
</tt></pre>
714 <div class=
"paragraph"><p>It shows that foo.png has differences from HEAD (but that is
715 binary so line count cannot be shown) and there is no
716 difference between indexed copy and the working tree
717 version (if the working tree version were also different,
718 <em>binary
</em> would have been shown in place of
<em>nothing
</em>). The
719 other file, git-add
--interactive.perl, has
403 lines added
720 and
35 lines deleted if you commit what is in the index, but
721 working tree file has further modifications (one addition and
722 one deletion).
</p></div>
729 This shows the status information and issues an
"Update>>"
730 prompt. When the prompt ends with double
<em>>></em>, you can
731 make more than one selection, concatenated with whitespace or
732 comma. Also you can say ranges. E.g.
"2-5 7,9" to choose
733 2,
3,
4,
5,
7,
9 from the list. If the second number in a range is
734 omitted, all remaining patches are taken. E.g.
"7-" to choose
735 7,
8,
9 from the list. You can say
<em>*
</em> to choose everything.
737 <div class=
"paragraph"><p>What you chose are then highlighted with
<em>*
</em>,
739 <div class=
"listingblock">
740 <div class=
"content">
741 <pre><tt> staged unstaged path
742 1: binary nothing foo.png
743 *
2: +
403/-
35 +
1/-
1 git-add--interactive.perl
</tt></pre>
745 <div class=
"paragraph"><p>To remove selection, prefix the input with
<tt>-
</tt>
747 <div class=
"listingblock">
748 <div class=
"content">
749 <pre><tt>Update
>> -
2</tt></pre>
751 <div class=
"paragraph"><p>After making the selection, answer with an empty line to stage the
752 contents of working tree files for selected paths in the index.
</p></div>
759 This has a very similar UI to
<em>update
</em>, and the staged
760 information for selected paths are reverted to that of the
761 HEAD version. Reverting new paths makes them untracked.
769 This has a very similar UI to
<em>update
</em> and
770 <em>revert
</em>, and lets you add untracked paths to the index.
778 This lets you choose one path out of a
<em>status
</em> like selection.
779 After choosing the path, it presents the diff between the index
780 and the working tree file and asks you if you want to stage
781 the change of each hunk. You can say:
783 <div class=
"literalblock">
784 <div class=
"content">
785 <pre><tt>y - stage this hunk
786 n - do not stage this hunk
787 q - quit; do not stage this hunk nor any of the remaining ones
788 a - stage this hunk and all later hunks in the file
789 d - do not stage this hunk nor any of the later hunks in the file
790 g - select a hunk to go to
791 / - search for a hunk matching the given regex
792 j - leave this hunk undecided, see next undecided hunk
793 J - leave this hunk undecided, see next hunk
794 k - leave this hunk undecided, see previous undecided hunk
795 K - leave this hunk undecided, see previous hunk
796 s - split the current hunk into smaller hunks
797 e - manually edit the current hunk
798 ? - print help
</tt></pre>
800 <div class=
"paragraph"><p>After deciding the fate for all hunks, if there is any hunk
801 that was chosen, the index is updated with the selected hunks.
</p></div>
808 This lets you review what will be committed (i.e. between
814 <h2 id=
"_editing_patches">EDITING PATCHES
</h2>
815 <div class=
"sectionbody">
816 <div class=
"paragraph"><p>Invoking
<tt>git add -e
</tt> or selecting
<tt>e
</tt> from the interactive hunk
817 selector will open a patch in your editor; after the editor exits, the
818 result is applied to the index. You are free to make arbitrary changes
819 to the patch, but note that some changes may have confusing results, or
820 even result in a patch that cannot be applied. If you want to abort the
821 operation entirely (i.e., stage nothing new in the index), simply delete
822 all lines of the patch. The list below describes some common things you
823 may see in a patch, and which editing operations make sense on them.
</p></div>
824 <div class=
"dlist"><dl>
830 Added content is represented by lines beginning with
"+". You can
831 prevent staging any addition lines by deleting them.
839 Removed content is represented by lines beginning with
"-". You can
840 prevent staging their removal by converting the
"-" to a
" " (space).
848 Modified content is represented by
"-" lines (removing the old content)
849 followed by
"+" lines (adding the replacement content). You can
850 prevent staging the modification by converting
"-" lines to
" ", and
851 removing
"+" lines. Beware that modifying only half of the pair is
852 likely to introduce confusing changes to the index.
856 <div class=
"paragraph"><p>There are also more complex operations that can be performed. But beware
857 that because the patch is applied only to the index and not the working
858 tree, the working tree will appear to
"undo" the change in the index.
859 For example, introducing a new line into the index that is in neither
860 the HEAD nor the working tree will stage the new line for commit, but
861 the line will appear to be reverted in the working tree.
</p></div>
862 <div class=
"paragraph"><p>Avoid using these constructs, or do so with extreme caution.
</p></div>
863 <div class=
"dlist"><dl>
865 removing untouched content
869 Content which does not differ between the index and working tree may be
870 shown on context lines, beginning with a
" " (space). You can stage
871 context lines for removal by converting the space to a
"-". The
872 resulting working tree file will appear to re-add the content.
876 modifying existing content
880 One can also modify context lines by staging them for removal (by
881 converting
" " to
"-") and adding a
"+" line with the new content.
882 Similarly, one can modify
"+" lines for existing additions or
883 modifications. In all cases, the new modification will appear reverted
892 You may also add new content that does not exist in the patch; simply
893 add new lines, each starting with
"+". The addition will appear
894 reverted in the working tree.
898 <div class=
"paragraph"><p>There are also several operations which should be avoided entirely, as
899 they will make the patch impossible to apply:
</p></div>
900 <div class=
"ulist"><ul>
903 adding context (
" ") or removal (
"-") lines
908 deleting context or removal lines
913 modifying the contents of context or removal lines
918 <h2 id=
"_see_also">SEE ALSO
</h2>
919 <div class=
"sectionbody">
920 <div class=
"paragraph"><p><a href=
"git-status.html">git-status(
1)
</a>
921 <a href=
"git-rm.html">git-rm(
1)
</a>
922 <a href=
"git-reset.html">git-reset(
1)
</a>
923 <a href=
"git-mv.html">git-mv(
1)
</a>
924 <a href=
"git-commit.html">git-commit(
1)
</a>
925 <a href=
"git-update-index.html">git-update-index(
1)
</a></p></div>
927 <h2 id=
"_git">GIT
</h2>
928 <div class=
"sectionbody">
929 <div class=
"paragraph"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
932 <div id=
"footer-text">
933 Last updated
2011-
05-
05 01:
29:
54 UTC