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.
620 This option can only be used together with --dry-run. By using
621 this option the user can check if any of the given files would
622 be ignored, no matter if they are already present in the work
631 This option can be used to separate command-line options from
632 the list of files, (useful when filenames might be mistaken
633 for command-line options).
638 <h2 id=
"_configuration">Configuration
</h2>
639 <div class=
"sectionbody">
640 <div class=
"paragraph"><p>The optional configuration variable
<tt>core.excludesfile
</tt> indicates a path to a
641 file containing patterns of file names to exclude from git-add, similar to
642 $GIT_DIR/info/exclude. Patterns in the exclude file are used in addition to
643 those in info/exclude. See
<a href=
"gitrepository-layout.html">gitrepository-layout(
5)
</a>.
</p></div>
645 <h2 id=
"_examples">EXAMPLES
</h2>
646 <div class=
"sectionbody">
647 <div class=
"ulist"><ul>
650 Adds content from all
<tt>*.txt
</tt> files under
<tt>Documentation
</tt> directory
651 and its subdirectories:
653 <div class=
"listingblock">
654 <div class=
"content">
655 <pre><tt>$ git add Documentation/\*.txt
</tt></pre>
657 <div class=
"paragraph"><p>Note that the asterisk
<tt>*
</tt> is quoted from the shell in this
658 example; this lets the command include the files from
659 subdirectories of
<tt>Documentation/
</tt> directory.
</p></div>
663 Considers adding content from all git-*.sh scripts:
665 <div class=
"listingblock">
666 <div class=
"content">
667 <pre><tt>$ git add git-*.sh
</tt></pre>
669 <div class=
"paragraph"><p>Because this example lets the shell expand the asterisk (i.e. you are
670 listing the files explicitly), it does not consider
671 <tt>subdir/git-foo.sh
</tt>.
</p></div>
675 <h2 id=
"_interactive_mode">Interactive mode
</h2>
676 <div class=
"sectionbody">
677 <div class=
"paragraph"><p>When the command enters the interactive mode, it shows the
678 output of the
<em>status
</em> subcommand, and then goes into its
679 interactive command loop.
</p></div>
680 <div class=
"paragraph"><p>The command loop shows the list of subcommands available, and
681 gives a prompt
"What now> ". In general, when the prompt ends
682 with a single
<em>></em>, you can pick only one of the choices given
683 and type return, like this:
</p></div>
684 <div class=
"listingblock">
685 <div class=
"content">
686 <pre><tt> *** Commands ***
687 1: status
2: update
3: revert
4: add untracked
688 5: patch
6: diff
7: quit
8: help
689 What now
> 1</tt></pre>
691 <div class=
"paragraph"><p>You also could say
<tt>s
</tt> or
<tt>sta
</tt> or
<tt>status
</tt> above as long as the
692 choice is unique.
</p></div>
693 <div class=
"paragraph"><p>The main command loop has
6 subcommands (plus help and quit).
</p></div>
694 <div class=
"dlist"><dl>
700 This shows the change between HEAD and index (i.e. what will be
701 committed if you say
<tt>git commit
</tt>), and between index and
702 working tree files (i.e. what you could stage further before
703 <tt>git commit
</tt> using
<tt>git add
</tt>) for each path. A sample output
706 <div class=
"listingblock">
707 <div class=
"content">
708 <pre><tt> staged unstaged path
709 1: binary nothing foo.png
710 2: +
403/-
35 +
1/-
1 git-add--interactive.perl
</tt></pre>
712 <div class=
"paragraph"><p>It shows that foo.png has differences from HEAD (but that is
713 binary so line count cannot be shown) and there is no
714 difference between indexed copy and the working tree
715 version (if the working tree version were also different,
716 <em>binary
</em> would have been shown in place of
<em>nothing
</em>). The
717 other file, git-add
--interactive.perl, has
403 lines added
718 and
35 lines deleted if you commit what is in the index, but
719 working tree file has further modifications (one addition and
720 one deletion).
</p></div>
727 This shows the status information and issues an
"Update>>"
728 prompt. When the prompt ends with double
<em>>></em>, you can
729 make more than one selection, concatenated with whitespace or
730 comma. Also you can say ranges. E.g.
"2-5 7,9" to choose
731 2,
3,
4,
5,
7,
9 from the list. If the second number in a range is
732 omitted, all remaining patches are taken. E.g.
"7-" to choose
733 7,
8,
9 from the list. You can say
<em>*
</em> to choose everything.
735 <div class=
"paragraph"><p>What you chose are then highlighted with
<em>*
</em>,
737 <div class=
"listingblock">
738 <div class=
"content">
739 <pre><tt> staged unstaged path
740 1: binary nothing foo.png
741 *
2: +
403/-
35 +
1/-
1 git-add--interactive.perl
</tt></pre>
743 <div class=
"paragraph"><p>To remove selection, prefix the input with
<tt>-
</tt>
745 <div class=
"listingblock">
746 <div class=
"content">
747 <pre><tt>Update
>> -
2</tt></pre>
749 <div class=
"paragraph"><p>After making the selection, answer with an empty line to stage the
750 contents of working tree files for selected paths in the index.
</p></div>
757 This has a very similar UI to
<em>update
</em>, and the staged
758 information for selected paths are reverted to that of the
759 HEAD version. Reverting new paths makes them untracked.
767 This has a very similar UI to
<em>update
</em> and
768 <em>revert
</em>, and lets you add untracked paths to the index.
776 This lets you choose one path out of a
<em>status
</em> like selection.
777 After choosing the path, it presents the diff between the index
778 and the working tree file and asks you if you want to stage
779 the change of each hunk. You can say:
781 <div class=
"literalblock">
782 <div class=
"content">
783 <pre><tt>y - stage this hunk
784 n - do not stage this hunk
785 q - quit; do not stage this hunk nor any of the remaining ones
786 a - stage this hunk and all later hunks in the file
787 d - do not stage this hunk nor any of the later hunks in the file
788 g - select a hunk to go to
789 / - search for a hunk matching the given regex
790 j - leave this hunk undecided, see next undecided hunk
791 J - leave this hunk undecided, see next hunk
792 k - leave this hunk undecided, see previous undecided hunk
793 K - leave this hunk undecided, see previous hunk
794 s - split the current hunk into smaller hunks
795 e - manually edit the current hunk
796 ? - print help
</tt></pre>
798 <div class=
"paragraph"><p>After deciding the fate for all hunks, if there is any hunk
799 that was chosen, the index is updated with the selected hunks.
</p></div>
806 This lets you review what will be committed (i.e. between
812 <h2 id=
"_editing_patches">EDITING PATCHES
</h2>
813 <div class=
"sectionbody">
814 <div class=
"paragraph"><p>Invoking
<tt>git add -e
</tt> or selecting
<tt>e
</tt> from the interactive hunk
815 selector will open a patch in your editor; after the editor exits, the
816 result is applied to the index. You are free to make arbitrary changes
817 to the patch, but note that some changes may have confusing results, or
818 even result in a patch that cannot be applied. If you want to abort the
819 operation entirely (i.e., stage nothing new in the index), simply delete
820 all lines of the patch. The list below describes some common things you
821 may see in a patch, and which editing operations make sense on them.
</p></div>
822 <div class=
"dlist"><dl>
828 Added content is represented by lines beginning with
"+". You can
829 prevent staging any addition lines by deleting them.
837 Removed content is represented by lines beginning with
"-". You can
838 prevent staging their removal by converting the
"-" to a
" " (space).
846 Modified content is represented by
"-" lines (removing the old content)
847 followed by
"+" lines (adding the replacement content). You can
848 prevent staging the modification by converting
"-" lines to
" ", and
849 removing
"+" lines. Beware that modifying only half of the pair is
850 likely to introduce confusing changes to the index.
854 <div class=
"paragraph"><p>There are also more complex operations that can be performed. But beware
855 that because the patch is applied only to the index and not the working
856 tree, the working tree will appear to
"undo" the change in the index.
857 For example, introducing a new line into the index that is in neither
858 the HEAD nor the working tree will stage the new line for commit, but
859 the line will appear to be reverted in the working tree.
</p></div>
860 <div class=
"paragraph"><p>Avoid using these constructs, or do so with extreme caution.
</p></div>
861 <div class=
"dlist"><dl>
863 removing untouched content
867 Content which does not differ between the index and working tree may be
868 shown on context lines, beginning with a
" " (space). You can stage
869 context lines for removal by converting the space to a
"-". The
870 resulting working tree file will appear to re-add the content.
874 modifying existing content
878 One can also modify context lines by staging them for removal (by
879 converting
" " to
"-") and adding a
"+" line with the new content.
880 Similarly, one can modify
"+" lines for existing additions or
881 modifications. In all cases, the new modification will appear reverted
890 You may also add new content that does not exist in the patch; simply
891 add new lines, each starting with
"+". The addition will appear
892 reverted in the working tree.
896 <div class=
"paragraph"><p>There are also several operations which should be avoided entirely, as
897 they will make the patch impossible to apply:
</p></div>
898 <div class=
"ulist"><ul>
901 adding context (
" ") or removal (
"-") lines
906 deleting context or removal lines
911 modifying the contents of context or removal lines
916 <h2 id=
"_see_also">SEE ALSO
</h2>
917 <div class=
"sectionbody">
918 <div class=
"paragraph"><p><a href=
"git-status.html">git-status(
1)
</a>
919 <a href=
"git-rm.html">git-rm(
1)
</a>
920 <a href=
"git-reset.html">git-reset(
1)
</a>
921 <a href=
"git-mv.html">git-mv(
1)
</a>
922 <a href=
"git-commit.html">git-commit(
1)
</a>
923 <a href=
"git-update-index.html">git-update-index(
1)
</a></p></div>
925 <h2 id=
"_author">Author
</h2>
926 <div class=
"sectionbody">
927 <div class=
"paragraph"><p>Written by Linus Torvalds
<<a href=
"mailto:torvalds@osdl.org">torvalds@osdl.org
</a>></p></div>
929 <h2 id=
"_documentation">Documentation
</h2>
930 <div class=
"sectionbody">
931 <div class=
"paragraph"><p>Documentation by Junio C Hamano and the git-list
<<a href=
"mailto:git@vger.kernel.org">git@vger.kernel.org
</a>>.
</p></div>
933 <h2 id=
"_git">GIT
</h2>
934 <div class=
"sectionbody">
935 <div class=
"paragraph"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
938 <div id=
"footer-text">
939 Last updated
2011-
01-
04 22:
05:
44 UTC