Autogenerated HTML docs for v1.7.3-rc0-38-g9ab5a
[git/jnareb-git.git] / git-add.html
blobd06ac99a7973f69cf3fdcef2e4038447a813da9d
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">
4 <head>
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">
8 /* Debug borders */
9 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
11 border: 1px solid red;
15 body {
16 margin: 1em 5% 1em 5%;
19 a {
20 color: blue;
21 text-decoration: underline;
23 a:visited {
24 color: fuchsia;
27 em {
28 font-style: italic;
31 strong {
32 font-weight: bold;
35 tt {
36 color: navy;
39 h1, h2, h3, h4, h5, h6 {
40 color: #527bbd;
41 font-family: sans-serif;
42 margin-top: 1.2em;
43 margin-bottom: 0.5em;
44 line-height: 1.3;
47 h1, h2, h3 {
48 border-bottom: 2px solid silver;
50 h2 {
51 padding-top: 0.5em;
53 h3 {
54 float: left;
56 h3 + * {
57 clear: left;
60 div.sectionbody {
61 font-family: serif;
62 margin-left: 0;
65 hr {
66 border: 1px solid silver;
69 p {
70 margin-top: 0.5em;
71 margin-bottom: 0.5em;
74 pre {
75 padding: 0;
76 margin: 0;
79 span#author {
80 color: #527bbd;
81 font-family: sans-serif;
82 font-weight: bold;
83 font-size: 1.1em;
85 span#email {
87 span#revision {
88 font-family: sans-serif;
91 div#footer {
92 font-family: sans-serif;
93 font-size: small;
94 border-top: 2px solid silver;
95 padding-top: 0.5em;
96 margin-top: 4.0em;
98 div#footer-text {
99 float: left;
100 padding-bottom: 0.5em;
102 div#footer-badges {
103 float: right;
104 padding-bottom: 0.5em;
107 div#preamble,
108 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
109 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
110 div.admonitionblock {
111 margin-right: 10%;
112 margin-top: 1.5em;
113 margin-bottom: 1.5em;
115 div.admonitionblock {
116 margin-top: 2.5em;
117 margin-bottom: 2.5em;
120 div.content { /* Block element content. */
121 padding: 0;
124 /* Block element titles. */
125 div.title, caption.title {
126 font-family: sans-serif;
127 font-weight: bold;
128 text-align: left;
129 margin-top: 1.0em;
130 margin-bottom: 0.5em;
132 div.title + * {
133 margin-top: 0;
136 td div.title:first-child {
137 margin-top: 0.0em;
139 div.content div.title:first-child {
140 margin-top: 0.0em;
142 div.content + div.title {
143 margin-top: 0.0em;
146 div.sidebarblock > div.content {
147 background: #ffffee;
148 border: 1px solid silver;
149 padding: 0.5em;
152 div.listingblock {
153 margin-right: 0%;
155 div.listingblock > div.content {
156 border: 1px solid silver;
157 background: #f4f4f4;
158 padding: 0.5em;
161 div.quoteblock > div.content {
162 padding-left: 2.0em;
165 div.attribution {
166 text-align: right;
168 div.verseblock + div.attribution {
169 text-align: left;
172 div.admonitionblock .icon {
173 vertical-align: top;
174 font-size: 1.1em;
175 font-weight: bold;
176 text-decoration: underline;
177 color: #527bbd;
178 padding-right: 0.5em;
180 div.admonitionblock td.content {
181 padding-left: 0.5em;
182 border-left: 2px solid silver;
185 div.exampleblock > div.content {
186 border-left: 2px solid silver;
187 padding: 0.5em;
190 div.verseblock div.content {
191 white-space: pre;
194 div.imageblock div.content { padding-left: 0; }
195 div.imageblock img { border: 1px solid silver; }
196 span.image img { border-style: none; }
198 dl {
199 margin-top: 0.8em;
200 margin-bottom: 0.8em;
202 dt {
203 margin-top: 0.5em;
204 margin-bottom: 0;
205 font-style: italic;
207 dd > *:first-child {
208 margin-top: 0;
211 ul, ol {
212 list-style-position: outside;
214 div.olist2 ol {
215 list-style-type: lower-alpha;
218 div.tableblock > table {
219 border: 3px solid #527bbd;
221 thead {
222 font-family: sans-serif;
223 font-weight: bold;
225 tfoot {
226 font-weight: bold;
229 div.hlist {
230 margin-top: 0.8em;
231 margin-bottom: 0.8em;
233 div.hlist td {
234 padding-bottom: 5px;
236 td.hlist1 {
237 vertical-align: top;
238 font-style: italic;
239 padding-right: 0.8em;
241 td.hlist2 {
242 vertical-align: top;
245 @media print {
246 div#footer-badges { display: none; }
249 div#toctitle {
250 color: #527bbd;
251 font-family: sans-serif;
252 font-size: 1.1em;
253 font-weight: bold;
254 margin-top: 1.0em;
255 margin-bottom: 0.1em;
258 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
259 margin-top: 0;
260 margin-bottom: 0;
262 div.toclevel2 {
263 margin-left: 2em;
264 font-size: 0.9em;
266 div.toclevel3 {
267 margin-left: 4em;
268 font-size: 0.9em;
270 div.toclevel4 {
271 margin-left: 6em;
272 font-size: 0.9em;
274 include1::./stylesheets/xhtml11-manpage.css[]
275 /* Workarounds for IE6's broken and incomplete CSS2. */
277 div.sidebar-content {
278 background: #ffffee;
279 border: 1px solid silver;
280 padding: 0.5em;
282 div.sidebar-title, div.image-title {
283 font-family: sans-serif;
284 font-weight: bold;
285 margin-top: 0.0em;
286 margin-bottom: 0.5em;
289 div.listingblock div.content {
290 border: 1px solid silver;
291 background: #f4f4f4;
292 padding: 0.5em;
295 div.quoteblock-content {
296 padding-left: 2.0em;
299 div.exampleblock-content {
300 border-left: 2px solid silver;
301 padding-left: 0.5em;
304 /* IE6 sets dynamically generated links as visited. */
305 div#toc a:visited { color: blue; }
306 </style>
307 <title>git-add(1)</title>
308 </head>
309 <body>
310 <div id="header">
311 <h1>
312 git-add(1) Manual Page
313 </h1>
314 <h2>NAME</h2>
315 <div class="sectionbody">
316 <p>git-add -
317 Add file contents to the index
318 </p>
319 </div>
320 </div>
321 <h2>SYNOPSIS</h2>
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 [&lt;filepattern&gt;&#8230;]</div></div>
328 </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
355 commit.</p></div>
356 </div>
357 <h2 id="_options">OPTIONS</h2>
358 <div class="sectionbody">
359 <div class="vlist"><dl>
360 <dt>
361 &lt;filepattern&gt;&#8230;
362 </dt>
363 <dd>
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.
370 </p>
371 </dd>
372 <dt>
374 </dt>
375 <dt>
376 --dry-run
377 </dt>
378 <dd>
380 Don't actually add the file(s), just show if they exist and/or will
381 be ignored.
382 </p>
383 </dd>
384 <dt>
386 </dt>
387 <dt>
388 --verbose
389 </dt>
390 <dd>
392 Be verbose.
393 </p>
394 </dd>
395 <dt>
397 </dt>
398 <dt>
399 --force
400 </dt>
401 <dd>
403 Allow adding otherwise ignored files.
404 </p>
405 </dd>
406 <dt>
408 </dt>
409 <dt>
410 --interactive
411 </dt>
412 <dd>
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 &#8220;Interactive
417 mode&#8221; for details.
418 </p>
419 </dd>
420 <dt>
422 </dt>
423 <dt>
424 --patch
425 </dt>
426 <dd>
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
431 index.
432 </p>
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 &#8220;Interactive mode&#8221; for details.</p></div>
436 </dd>
437 <dt>
438 -e, --edit
439 </dt>
440 <dd>
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.
445 </p>
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
448 apply.</p></div>
449 </dd>
450 <dt>
452 </dt>
453 <dt>
454 --update
455 </dt>
456 <dd>
458 Only match &lt;filepattern&gt; 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
463 have been removed.
464 </p>
465 <div class="para"><p>If no &lt;filepattern&gt; is given, default to "."; in other words,
466 update all tracked files in the current directory and its
467 subdirectories.</p></div>
468 </dd>
469 <dt>
471 </dt>
472 <dt>
473 --all
474 </dt>
475 <dd>
477 Like <tt>-u</tt>, but match &lt;filepattern&gt; 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.
481 </p>
482 </dd>
483 <dt>
485 </dt>
486 <dt>
487 --intent-to-add
488 </dt>
489 <dd>
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
495 -a</tt>.
496 </p>
497 </dd>
498 <dt>
499 --refresh
500 </dt>
501 <dd>
503 Don't add the file(s), but only refresh their stat()
504 information in the index.
505 </p>
506 </dd>
507 <dt>
508 --ignore-errors
509 </dt>
510 <dd>
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.
515 </p>
516 </dd>
517 <dt>
518 --ignore-missing
519 </dt>
520 <dd>
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
525 tree or not.
526 </p>
527 </dd>
528 <dt>
530 </dt>
531 <dd>
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).
536 </p>
537 </dd>
538 </dl></div>
539 </div>
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>
546 </div>
547 <h2 id="_examples">EXAMPLES</h2>
548 <div class="sectionbody">
549 <div class="ilist"><ul>
550 <li>
552 Adds content from all <tt>*.txt</tt> files under <tt>Documentation</tt> directory
553 and its subdirectories:
554 </p>
555 <div class="listingblock">
556 <div class="content">
557 <pre><tt>$ git add Documentation/\*.txt</tt></pre>
558 </div></div>
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>
562 </li>
563 <li>
565 Considers adding content from all git-*.sh scripts:
566 </p>
567 <div class="listingblock">
568 <div class="content">
569 <pre><tt>$ git add git-*.sh</tt></pre>
570 </div></div>
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>
574 </li>
575 </ul></div>
576 </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&gt; ". In general, when the prompt ends
584 with a single <em>&gt;</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&gt; 1</tt></pre>
592 </div></div>
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>
597 <dt>
598 status
599 </dt>
600 <dd>
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
606 looks like this:
607 </p>
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>
613 </div></div>
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&#45;&#45;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>
623 </dd>
624 <dt>
625 update
626 </dt>
627 <dd>
629 This shows the status information and issues an "Update&gt;&gt;"
630 prompt. When the prompt ends with double <em>&gt;&gt;</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.
636 </p>
637 <div class="para"><p>What you chose are then highlighted with <em>*</em>,
638 like this:</p></div>
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>
644 </div></div>
645 <div class="para"><p>To remove selection, prefix the input with <tt>-</tt>
646 like this:</p></div>
647 <div class="listingblock">
648 <div class="content">
649 <pre><tt>Update&gt;&gt; -2</tt></pre>
650 </div></div>
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>
653 </dd>
654 <dt>
655 revert
656 </dt>
657 <dd>
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.
662 </p>
663 </dd>
664 <dt>
665 add untracked
666 </dt>
667 <dd>
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.
671 </p>
672 </dd>
673 <dt>
674 patch
675 </dt>
676 <dd>
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:
682 </p>
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>
699 </div></div>
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>
702 </dd>
703 <dt>
704 diff
705 </dt>
706 <dd>
708 This lets you review what will be committed (i.e. between
709 HEAD and index).
710 </p>
711 </dd>
712 </dl></div>
713 </div>
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>
722 </div>
723 <h2 id="_author">Author</h2>
724 <div class="sectionbody">
725 <div class="para"><p>Written by Linus Torvalds &lt;torvalds@osdl.org&gt;</p></div>
726 </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 &lt;git@vger.kernel.org&gt;.</p></div>
730 </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>
734 </div>
735 <div id="footer">
736 <div id="footer-text">
737 Last updated 2010-09-03 21:29:58 UTC
738 </div>
739 </div>
740 </body>
741 </html>