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.2.5" />
7 <style type=
"text/css">
9 p
, li
, dt
, dd
, div
, pre
, h1
, h2
, h3
, h4
, h5
, h6
{
11 border: 1px solid red;
16 margin: 1em 5% 1em 5%;
21 text-decoration: underline
;
39 h1
, h2
, h3
, h4
, h5
, h6
{
41 font-family: sans-serif
;
48 border-bottom: 2px solid silver
;
66 border: 1px solid silver
;
81 font-family: sans-serif
;
88 font-family: sans-serif
;
92 font-family: sans-serif
;
94 border-top: 2px solid silver
;
100 padding-bottom: 0.5em;
104 padding-bottom: 0.5em;
108 div
.tableblock
, div
.imageblock
, div
.exampleblock
, div
.verseblock
,
109 div
.quoteblock
, div
.literalblock
, div
.listingblock
, div
.sidebarblock
,
110 div
.admonitionblock
{
113 margin-bottom: 1.5em;
115 div
.admonitionblock
{
117 margin-bottom: 2.5em;
120 div
.content
{ /* Block element content. */
124 /* Block element titles. */
125 div
.title
, caption
.title
{
126 font-family: sans-serif
;
130 margin-bottom: 0.5em;
136 td div
.title:first-child
{
139 div
.content div
.title:first-child
{
142 div
.content
+ div
.title
{
146 div
.sidebarblock
> div
.content
{
148 border: 1px solid silver
;
155 div
.listingblock
> div
.content
{
156 border: 1px solid silver
;
161 div
.quoteblock
> div
.content
{
168 div
.verseblock
+ div
.attribution
{
172 div
.admonitionblock
.icon
{
176 text-decoration: underline
;
178 padding-right: 0.5em;
180 div
.admonitionblock td
.content
{
182 border-left: 2px solid silver
;
185 div
.exampleblock
> div
.content
{
186 border-left: 2px solid silver
;
190 div
.verseblock div
.content
{
194 div
.imageblock div
.content
{ padding-left: 0; }
195 div
.imageblock img
{ border: 1px solid silver
; }
196 span
.image img
{ border-style: none
; }
200 margin-bottom: 0.8em;
212 list-style-position: outside
;
215 list-style-type: lower-alpha
;
218 div
.tableblock
> table
{
219 border: 3px solid
#527bbd;
222 font-family: sans-serif
;
231 margin-bottom: 0.8em;
239 padding-right: 0.8em;
246 div#footer-badges
{ display: none
; }
251 font-family: sans-serif
;
255 margin-bottom: 0.1em;
258 div
.toclevel1
, div
.toclevel2
, div
.toclevel3
, div
.toclevel4
{
274 include1::./stylesheets
/xhtml11-manpage
.css
[]
275 /* Workarounds for IE6's broken and incomplete CSS2. */
277 div
.sidebar-content
{
279 border: 1px solid silver
;
282 div
.sidebar-title
, div
.image-title
{
283 font-family: sans-serif
;
286 margin-bottom: 0.5em;
289 div
.listingblock div
.content
{
290 border: 1px solid silver
;
295 div
.quoteblock-content
{
299 div
.exampleblock-content
{
300 border-left: 2px solid silver
;
304 /* IE6 sets dynamically generated links as visited. */
305 div#toc
a:visited
{ color: blue
; }
307 <title>git-add(
1)
</title>
312 git-add(
1) Manual Page
315 <div class=
"sectionbody">
317 Add file contents to the index
322 <div class=
"sectionbody">
323 <div class=
"verseblock">
324 <div class=
"content"><em>git add
</em> [-n] [-v] [--force | -f] [--interactive | -i] [--patch | -p]
325 [--edit | -e] [--all | [--update | -u]] [--intent-to-add | -N]
326 [--refresh] [--ignore-errors] [--ignore-missing] [--]
327 [
<filepattern
>…]
</div></div>
329 <h2 id=
"_description">DESCRIPTION
</h2>
330 <div class=
"sectionbody">
331 <div class=
"para"><p>This command updates the index using the current content found in
332 the working tree, to prepare the content staged for the next commit.
333 It typically adds the current content of existing paths as a whole,
334 but with some options it can also be used to add content with
335 only part of the changes made to the working tree files applied, or
336 remove paths that do not exist in the working tree anymore.
</p></div>
337 <div class=
"para"><p>The
"index" holds a snapshot of the content of the working tree, and it
338 is this snapshot that is taken as the contents of the next commit. Thus
339 after making any changes to the working directory, and before running
340 the commit command, you must use the
<tt>add
</tt> command to add any new or
341 modified files to the index.
</p></div>
342 <div class=
"para"><p>This command can be performed multiple times before a commit. It only
343 adds the content of the specified file(s) at the time the add command is
344 run; if you want subsequent changes included in the next commit, then
345 you must run
<tt>git add
</tt> again to add the new content to the index.
</p></div>
346 <div class=
"para"><p>The
<tt>git status
</tt> command can be used to obtain a summary of which
347 files have changes that are staged for the next commit.
</p></div>
348 <div class=
"para"><p>The
<tt>git add
</tt> command will not add ignored files by default. If any
349 ignored files were explicitly specified on the command line,
<tt>git add
</tt>
350 will fail with a list of ignored files. Ignored files reached by
351 directory recursion or filename globbing performed by Git (quote your
352 globs before the shell) will be silently ignored. The
<em>git add
</em> command can
353 be used to add ignored files with the
<tt>-f
</tt> (force) option.
</p></div>
354 <div class=
"para"><p>Please see
<a href=
"git-commit.html">git-commit(
1)
</a> for alternative ways to add content to a
357 <h2 id=
"_options">OPTIONS
</h2>
358 <div class=
"sectionbody">
359 <div class=
"vlist"><dl>
361 <filepattern
>…
365 Files to add content from. Fileglobs (e.g.
<tt>*.c
</tt>) can
366 be given to add all matching files. Also a
367 leading directory name (e.g.
<tt>dir
</tt> to add
<tt>dir/file1
</tt>
368 and
<tt>dir/file2
</tt>) can be given to add all files in the
369 directory, recursively.
380 Don't actually add the file(s), just show if they exist and/or will
403 Allow adding otherwise ignored files.
414 Add modified contents in the working tree interactively to
415 the index. Optional path arguments may be supplied to limit
416 operation to a subset of the working tree. See
“Interactive
417 mode
” for details.
428 Interactively choose hunks of patch between the index and the
429 work tree and add them to the index. This gives the user a chance
430 to review the difference before adding modified contents to the
433 <div class=
"para"><p>This effectively runs
<tt>add --interactive
</tt>, but bypasses the
434 initial command menu and directly jumps to the
<tt>patch
</tt> subcommand.
435 See
“Interactive mode
” for details.
</p></div>
442 Open the diff vs. the index in an editor and let the user
443 edit it. After the editor was closed, adjust the hunk headers
444 and apply the patch to the index.
446 <div class=
"para"><p><strong>NOTE
</strong>: Obviously, if you change anything else than the first character
447 on lines beginning with a space or a minus, the patch will no longer
458 Only match
<filepattern
> against already tracked files in
459 the index rather than the working tree. That means that it
460 will never stage new files, but that it will stage modified
461 new contents of tracked files and that it will remove files
462 from the index if the corresponding files in the working tree
465 <div class=
"para"><p>If no
<filepattern
> is given, default to
"."; in other words,
466 update all tracked files in the current directory and its
467 subdirectories.
</p></div>
477 Like
<tt>-u
</tt>, but match
<filepattern
> against files in the
478 working tree in addition to the index. That means that it
479 will find new files as well as staging modified content and
480 removing files that are no longer in the working tree.
491 Record only the fact that the path will be added later. An entry
492 for the path is placed in the index with no content. This is
493 useful for, among other things, showing the unstaged content of
494 such files with
<tt>git diff
</tt> and committing them with
<tt>git commit
503 Don't add the file(s), but only refresh their stat()
504 information in the index.
512 If some files could not be added because of errors indexing
513 them, do not abort the operation, but continue adding the
514 others. The command shall still exit with non-zero status.
522 This option can only be used together with --dry-run. By using
523 this option the user can check if any of the given files would
524 be ignored, no matter if they are already present in the work
533 This option can be used to separate command-line options from
534 the list of files, (useful when filenames might be mistaken
535 for command-line options).
540 <h2 id=
"_configuration">Configuration
</h2>
541 <div class=
"sectionbody">
542 <div class=
"para"><p>The optional configuration variable
<tt>core.excludesfile
</tt> indicates a path to a
543 file containing patterns of file names to exclude from git-add, similar to
544 $GIT_DIR/info/exclude. Patterns in the exclude file are used in addition to
545 those in info/exclude. See
<a href=
"gitrepository-layout.html">gitrepository-layout(
5)
</a>.
</p></div>
547 <h2 id=
"_examples">EXAMPLES
</h2>
548 <div class=
"sectionbody">
549 <div class=
"ilist"><ul>
552 Adds content from all
<tt>*.txt
</tt> files under
<tt>Documentation
</tt> directory
553 and its subdirectories:
555 <div class=
"listingblock">
556 <div class=
"content">
557 <pre><tt>$ git add Documentation/\*.txt
</tt></pre>
559 <div class=
"para"><p>Note that the asterisk
<tt>*
</tt> is quoted from the shell in this
560 example; this lets the command include the files from
561 subdirectories of
<tt>Documentation/
</tt> directory.
</p></div>
565 Considers adding content from all git-*.sh scripts:
567 <div class=
"listingblock">
568 <div class=
"content">
569 <pre><tt>$ git add git-*.sh
</tt></pre>
571 <div class=
"para"><p>Because this example lets the shell expand the asterisk (i.e. you are
572 listing the files explicitly), it does not consider
573 <tt>subdir/git-foo.sh
</tt>.
</p></div>
577 <h2 id=
"_interactive_mode">Interactive mode
</h2>
578 <div class=
"sectionbody">
579 <div class=
"para"><p>When the command enters the interactive mode, it shows the
580 output of the
<em>status
</em> subcommand, and then goes into its
581 interactive command loop.
</p></div>
582 <div class=
"para"><p>The command loop shows the list of subcommands available, and
583 gives a prompt
"What now> ". In general, when the prompt ends
584 with a single
<em>></em>, you can pick only one of the choices given
585 and type return, like this:
</p></div>
586 <div class=
"listingblock">
587 <div class=
"content">
588 <pre><tt> *** Commands ***
589 1: status
2: update
3: revert
4: add untracked
590 5: patch
6: diff
7: quit
8: help
591 What now
> 1</tt></pre>
593 <div class=
"para"><p>You also could say
<tt>s
</tt> or
<tt>sta
</tt> or
<tt>status
</tt> above as long as the
594 choice is unique.
</p></div>
595 <div class=
"para"><p>The main command loop has
6 subcommands (plus help and quit).
</p></div>
596 <div class=
"vlist"><dl>
602 This shows the change between HEAD and index (i.e. what will be
603 committed if you say
<tt>git commit
</tt>), and between index and
604 working tree files (i.e. what you could stage further before
605 <tt>git commit
</tt> using
<tt>git add
</tt>) for each path. A sample output
608 <div class=
"listingblock">
609 <div class=
"content">
610 <pre><tt> staged unstaged path
611 1: binary nothing foo.png
612 2: +
403/-
35 +
1/-
1 git-add--interactive.perl
</tt></pre>
614 <div class=
"para"><p>It shows that foo.png has differences from HEAD (but that is
615 binary so line count cannot be shown) and there is no
616 difference between indexed copy and the working tree
617 version (if the working tree version were also different,
618 <em>binary
</em> would have been shown in place of
<em>nothing
</em>). The
619 other file, git-add
--interactive.perl, has
403 lines added
620 and
35 lines deleted if you commit what is in the index, but
621 working tree file has further modifications (one addition and
622 one deletion).
</p></div>
629 This shows the status information and issues an
"Update>>"
630 prompt. When the prompt ends with double
<em>>></em>, you can
631 make more than one selection, concatenated with whitespace or
632 comma. Also you can say ranges. E.g.
"2-5 7,9" to choose
633 2,
3,
4,
5,
7,
9 from the list. If the second number in a range is
634 omitted, all remaining patches are taken. E.g.
"7-" to choose
635 7,
8,
9 from the list. You can say
<em>*
</em> to choose everything.
637 <div class=
"para"><p>What you chose are then highlighted with
<em>*
</em>,
639 <div class=
"listingblock">
640 <div class=
"content">
641 <pre><tt> staged unstaged path
642 1: binary nothing foo.png
643 *
2: +
403/-
35 +
1/-
1 git-add--interactive.perl
</tt></pre>
645 <div class=
"para"><p>To remove selection, prefix the input with
<tt>-
</tt>
647 <div class=
"listingblock">
648 <div class=
"content">
649 <pre><tt>Update
>> -
2</tt></pre>
651 <div class=
"para"><p>After making the selection, answer with an empty line to stage the
652 contents of working tree files for selected paths in the index.
</p></div>
659 This has a very similar UI to
<em>update
</em>, and the staged
660 information for selected paths are reverted to that of the
661 HEAD version. Reverting new paths makes them untracked.
669 This has a very similar UI to
<em>update
</em> and
670 <em>revert
</em>, and lets you add untracked paths to the index.
678 This lets you choose one path out of a
<em>status
</em> like selection.
679 After choosing the path, it presents the diff between the index
680 and the working tree file and asks you if you want to stage
681 the change of each hunk. You can say:
683 <div class=
"literalblock">
684 <div class=
"content">
685 <pre><tt>y - stage this hunk
686 n - do not stage this hunk
687 q - quit; do not stage this hunk nor any of the remaining ones
688 a - stage this hunk and all later hunks in the file
689 d - do not stage this hunk nor any of the later hunks in the file
690 g - select a hunk to go to
691 / - search for a hunk matching the given regex
692 j - leave this hunk undecided, see next undecided hunk
693 J - leave this hunk undecided, see next hunk
694 k - leave this hunk undecided, see previous undecided hunk
695 K - leave this hunk undecided, see previous hunk
696 s - split the current hunk into smaller hunks
697 e - manually edit the current hunk
698 ? - print help
</tt></pre>
700 <div class=
"para"><p>After deciding the fate for all hunks, if there is any hunk
701 that was chosen, the index is updated with the selected hunks.
</p></div>
708 This lets you review what will be committed (i.e. between
714 <h2 id=
"_see_also">SEE ALSO
</h2>
715 <div class=
"sectionbody">
716 <div class=
"para"><p><a href=
"git-status.html">git-status(
1)
</a>
717 <a href=
"git-rm.html">git-rm(
1)
</a>
718 <a href=
"git-reset.html">git-reset(
1)
</a>
719 <a href=
"git-mv.html">git-mv(
1)
</a>
720 <a href=
"git-commit.html">git-commit(
1)
</a>
721 <a href=
"git-update-index.html">git-update-index(
1)
</a></p></div>
723 <h2 id=
"_author">Author
</h2>
724 <div class=
"sectionbody">
725 <div class=
"para"><p>Written by Linus Torvalds
<torvalds@osdl.org
></p></div>
727 <h2 id=
"_documentation">Documentation
</h2>
728 <div class=
"sectionbody">
729 <div class=
"para"><p>Documentation by Junio C Hamano and the git-list
<git@vger.kernel.org
>.
</p></div>
731 <h2 id=
"_git">GIT
</h2>
732 <div class=
"sectionbody">
733 <div class=
"para"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
736 <div id=
"footer-text">
737 Last updated
2010-
09-
03 21:
29:
58 UTC