Updated git_doc to git 1.8
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / git-add.xml
blob28ea2f18acd120d29bc086b4015372bf950f6754
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE sect2 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">\r
3 \r
4 <sect2 lang="en" id="git-add(1)">\r
5     <title>git-add(1)</title>\r
6 <indexterm>\r
7 <primary>git-add(1)</primary>\r
8 </indexterm>\r
9 <simplesect id="git-add(1)__name">\r
10 <title>NAME</title>\r
11 <simpara>git-add - Add file contents to the index</simpara>\r
12 </simplesect>\r
13 <simplesect id="git-add(1)__synopsis">\r
14 <title>SYNOPSIS</title>\r
15 <blockquote>\r
16 <literallayout><emphasis>git add</emphasis> [-n] [-v] [--force | -f] [--interactive | -i] [--patch | -p]\r
17           [--edit | -e] [--all | [--update | -u]] [--intent-to-add | -N]\r
18           [--refresh] [--ignore-errors] [--ignore-missing] [--]\r
19           [&lt;filepattern&gt;&#8230;]</literallayout>\r
20 </blockquote>\r
21 </simplesect>\r
22 <simplesect id="git-add(1)__description">\r
23 <title>DESCRIPTION</title>\r
24 <simpara>This command updates the index using the current content found in\r
25 the working tree, to prepare the content staged for the next commit.\r
26 It typically adds the current content of existing paths as a whole,\r
27 but with some options it can also be used to add content with\r
28 only part of the changes made to the working tree files applied, or\r
29 remove paths that do not exist in the working tree anymore.</simpara>\r
30 <simpara>The "index" holds a snapshot of the content of the working tree, and it\r
31 is this snapshot that is taken as the contents of the next commit.  Thus\r
32 after making any changes to the working directory, and before running\r
33 the commit command, you must use the <emphasis>add</emphasis> command to add any new or\r
34 modified files to the index.</simpara>\r
35 <simpara>This command can be performed multiple times before a commit.  It only\r
36 adds the content of the specified file(s) at the time the add command is\r
37 run; if you want subsequent changes included in the next commit, then\r
38 you must run <emphasis>git add</emphasis> again to add the new content to the index.</simpara>\r
39 <simpara>The <emphasis>git status</emphasis> command can be used to obtain a summary of which\r
40 files have changes that are staged for the next commit.</simpara>\r
41 <simpara>The <emphasis>git add</emphasis> command will not add ignored files by default.  If any\r
42 ignored files were explicitly specified on the command line, <emphasis>git add</emphasis>\r
43 will fail with a list of ignored files.  Ignored files reached by\r
44 directory recursion or filename globbing performed by Git (quote your\r
45 globs before the shell) will be silently ignored.  The <emphasis>git add</emphasis> command can\r
46 be used to add ignored files with the <emphasis>-f</emphasis> (force) option.</simpara>\r
47 <simpara>Please see <xref linkend="git-commit(1)" /> for alternative ways to add content to a\r
48 commit.</simpara>\r
49 </simplesect>\r
50 <simplesect id="git-add(1)__options">\r
51 <title>OPTIONS</title>\r
52 <variablelist>\r
53 <varlistentry>\r
54 <term>\r
55 &lt;filepattern&gt;&#8230;\r
56 </term>\r
57 <listitem>\r
58 <simpara>\r
59         Files to add content from.  Fileglobs (e.g. <emphasis>*.c</emphasis>) can\r
60         be given to add all matching files.  Also a\r
61         leading directory name (e.g. <emphasis>dir</emphasis> to add <emphasis>dir/file1</emphasis>\r
62         and <emphasis>dir/file2</emphasis>) can be given to add all files in the\r
63         directory, recursively.\r
64 </simpara>\r
65 </listitem>\r
66 </varlistentry>\r
67 <varlistentry>\r
68 <term>\r
69 -n\r
70 </term>\r
71 <term>\r
72 --dry-run\r
73 </term>\r
74 <listitem>\r
75 <simpara>\r
76         Don't actually add the file(s), just show if they exist and/or will\r
77         be ignored.\r
78 </simpara>\r
79 </listitem>\r
80 </varlistentry>\r
81 <varlistentry>\r
82 <term>\r
83 -v\r
84 </term>\r
85 <term>\r
86 --verbose\r
87 </term>\r
88 <listitem>\r
89 <simpara>\r
90         Be verbose.\r
91 </simpara>\r
92 </listitem>\r
93 </varlistentry>\r
94 <varlistentry>\r
95 <term>\r
96 -f\r
97 </term>\r
98 <term>\r
99 --force\r
100 </term>\r
101 <listitem>\r
102 <simpara>\r
103         Allow adding otherwise ignored files.\r
104 </simpara>\r
105 </listitem>\r
106 </varlistentry>\r
107 <varlistentry>\r
108 <term>\r
109 -i\r
110 </term>\r
111 <term>\r
112 --interactive\r
113 </term>\r
114 <listitem>\r
115 <simpara>\r
116         Add modified contents in the working tree interactively to\r
117         the index. Optional path arguments may be supplied to limit\r
118         operation to a subset of the working tree. See Interactive\r
119         mode for details.\r
120 </simpara>\r
121 </listitem>\r
122 </varlistentry>\r
123 <varlistentry>\r
124 <term>\r
125 -p\r
126 </term>\r
127 <term>\r
128 --patch\r
129 </term>\r
130 <listitem>\r
131 <simpara>\r
132         Interactively choose hunks of patch between the index and the\r
133         work tree and add them to the index. This gives the user a chance\r
134         to review the difference before adding modified contents to the\r
135         index.\r
136 </simpara>\r
137 <simpara>This effectively runs <emphasis>add --interactive</emphasis>, but bypasses the\r
138 initial command menu and directly jumps to the <emphasis>patch</emphasis> subcommand.\r
139 See Interactive mode for details.</simpara>\r
140 </listitem>\r
141 </varlistentry>\r
142 <varlistentry>\r
143 <term>\r
144 -e, --edit\r
145 </term>\r
146 <listitem>\r
147 <simpara>\r
148         Open the diff vs. the index in an editor and let the user\r
149         edit it.  After the editor was closed, adjust the hunk headers\r
150         and apply the patch to the index.\r
151 </simpara>\r
152 <simpara>The intent of this option is to pick and choose lines of the patch to\r
153 apply, or even to modify the contents of lines to be staged. This can be\r
154 quicker and more flexible than using the interactive hunk selector.\r
155 However, it is easy to confuse oneself and create a patch that does not\r
156 apply to the index. See EDITING PATCHES below.</simpara>\r
157 </listitem>\r
158 </varlistentry>\r
159 <varlistentry>\r
160 <term>\r
161 -u\r
162 </term>\r
163 <term>\r
164 --update\r
165 </term>\r
166 <listitem>\r
167 <simpara>\r
168         Only match &lt;filepattern&gt; against already tracked files in\r
169         the index rather than the working tree. That means that it\r
170         will never stage new files, but that it will stage modified\r
171         new contents of tracked files and that it will remove files\r
172         from the index if the corresponding files in the working tree\r
173         have been removed.\r
174 </simpara>\r
175 <simpara>If no &lt;filepattern&gt; is given, default to "."; in other words,\r
176 update all tracked files in the current directory and its\r
177 subdirectories.</simpara>\r
178 </listitem>\r
179 </varlistentry>\r
180 <varlistentry>\r
181 <term>\r
182 -A\r
183 </term>\r
184 <term>\r
185 --all\r
186 </term>\r
187 <listitem>\r
188 <simpara>\r
189         Like <emphasis>-u</emphasis>, but match &lt;filepattern&gt; against files in the\r
190         working tree in addition to the index. That means that it\r
191         will find new files as well as staging modified content and\r
192         removing files that are no longer in the working tree.\r
193 </simpara>\r
194 </listitem>\r
195 </varlistentry>\r
196 <varlistentry>\r
197 <term>\r
198 -N\r
199 </term>\r
200 <term>\r
201 --intent-to-add\r
202 </term>\r
203 <listitem>\r
204 <simpara>\r
205         Record only the fact that the path will be added later. An entry\r
206         for the path is placed in the index with no content. This is\r
207         useful for, among other things, showing the unstaged content of\r
208         such files with <emphasis>git diff</emphasis> and committing them with <emphasis>git commit\r
209         -a</emphasis>.\r
210 </simpara>\r
211 </listitem>\r
212 </varlistentry>\r
213 <varlistentry>\r
214 <term>\r
215 --refresh\r
216 </term>\r
217 <listitem>\r
218 <simpara>\r
219         Don't add the file(s), but only refresh their stat()\r
220         information in the index.\r
221 </simpara>\r
222 </listitem>\r
223 </varlistentry>\r
224 <varlistentry>\r
225 <term>\r
226 --ignore-errors\r
227 </term>\r
228 <listitem>\r
229 <simpara>\r
230         If some files could not be added because of errors indexing\r
231         them, do not abort the operation, but continue adding the\r
232         others. The command shall still exit with non-zero status.\r
233         The configuration variable <emphasis>add.ignoreErrors</emphasis> can be set to\r
234         true to make this the default behaviour.\r
235 </simpara>\r
236 </listitem>\r
237 </varlistentry>\r
238 <varlistentry>\r
239 <term>\r
240 --ignore-missing\r
241 </term>\r
242 <listitem>\r
243 <simpara>\r
244         This option can only be used together with --dry-run. By using\r
245         this option the user can check if any of the given files would\r
246         be ignored, no matter if they are already present in the work\r
247         tree or not.\r
248 </simpara>\r
249 </listitem>\r
250 </varlistentry>\r
251 <varlistentry>\r
252 <term>\r
253 --\r
254 </term>\r
255 <listitem>\r
256 <simpara>\r
257         This option can be used to separate command-line options from\r
258         the list of files, (useful when filenames might be mistaken\r
259         for command-line options).\r
260 </simpara>\r
261 </listitem>\r
262 </varlistentry>\r
263 </variablelist>\r
264 </simplesect>\r
265 <simplesect id="git-add(1)__configuration">\r
266 <title>Configuration</title>\r
267 <simpara>The optional configuration variable <emphasis>core.excludesfile</emphasis> indicates a path to a\r
268 file containing patterns of file names to exclude from git-add, similar to\r
269 $GIT_DIR/info/exclude.  Patterns in the exclude file are used in addition to\r
270 those in info/exclude.  See <xref linkend="gitignore(5)" />.</simpara>\r
271 </simplesect>\r
272 <simplesect id="git-add(1)__examples">\r
273 <title>EXAMPLES</title>\r
274 <itemizedlist>\r
275 <listitem>\r
276 <simpara>\r
277 Adds content from all <emphasis>*.txt</emphasis> files under <emphasis>Documentation</emphasis> directory\r
278 and its subdirectories:\r
279 </simpara>\r
280 <screen>$ git add Documentation/\*.txt</screen>\r
281 <simpara>Note that the asterisk <emphasis>*</emphasis> is quoted from the shell in this\r
282 example; this lets the command include the files from\r
283 subdirectories of <emphasis>Documentation/</emphasis> directory.</simpara>\r
284 </listitem>\r
285 <listitem>\r
286 <simpara>\r
287 Considers adding content from all git-*.sh scripts:\r
288 </simpara>\r
289 <screen>$ git add git-*.sh</screen>\r
290 <simpara>Because this example lets the shell expand the asterisk (i.e. you are\r
291 listing the files explicitly), it does not consider\r
292 <emphasis>subdir/git-foo.sh</emphasis>.</simpara>\r
293 </listitem>\r
294 </itemizedlist>\r
295 </simplesect>\r
296 <simplesect id="git-add(1)__interactive_mode">\r
297 <title>Interactive mode</title>\r
298 <simpara>When the command enters the interactive mode, it shows the\r
299 output of the <emphasis>status</emphasis> subcommand, and then goes into its\r
300 interactive command loop.</simpara>\r
301 <simpara>The command loop shows the list of subcommands available, and\r
302 gives a prompt "What now&gt; ".  In general, when the prompt ends\r
303 with a single <emphasis>&gt;</emphasis>, you can pick only one of the choices given\r
304 and type return, like this:</simpara>\r
305 <screen>    *** Commands ***\r
306       1: status       2: update       3: revert       4: add untracked\r
307       5: patch        6: diff         7: quit         8: help\r
308     What now&gt; 1</screen>\r
309 <simpara>You also could say <emphasis>s</emphasis> or <emphasis>sta</emphasis> or <emphasis>status</emphasis> above as long as the\r
310 choice is unique.</simpara>\r
311 <simpara>The main command loop has 6 subcommands (plus help and quit).</simpara>\r
312 <variablelist>\r
313 <varlistentry>\r
314 <term>\r
315 status\r
316 </term>\r
317 <listitem>\r
318 <simpara>\r
319    This shows the change between HEAD and index (i.e. what will be\r
320    committed if you say <emphasis>git commit</emphasis>), and between index and\r
321    working tree files (i.e. what you could stage further before\r
322    <emphasis>git commit</emphasis> using <emphasis>git add</emphasis>) for each path.  A sample output\r
323    looks like this:\r
324 </simpara>\r
325 <screen>              staged     unstaged path\r
326      1:       binary      nothing foo.png\r
327      2:     +403/-35        +1/-1 git-add--interactive.perl</screen>\r
328 <simpara>It shows that foo.png has differences from HEAD (but that is\r
329 binary so line count cannot be shown) and there is no\r
330 difference between indexed copy and the working tree\r
331 version (if the working tree version were also different,\r
332 <emphasis>binary</emphasis> would have been shown in place of <emphasis>nothing</emphasis>).  The\r
333 other file, git-add&#45;&#45;interactive.perl, has 403 lines added\r
334 and 35 lines deleted if you commit what is in the index, but\r
335 working tree file has further modifications (one addition and\r
336 one deletion).</simpara>\r
337 </listitem>\r
338 </varlistentry>\r
339 <varlistentry>\r
340 <term>\r
341 update\r
342 </term>\r
343 <listitem>\r
344 <simpara>\r
345    This shows the status information and issues an "Update&gt;&gt;"\r
346    prompt.  When the prompt ends with double <emphasis>&gt;&gt;</emphasis>, you can\r
347    make more than one selection, concatenated with whitespace or\r
348    comma.  Also you can say ranges.  E.g. "2-5 7,9" to choose\r
349    2,3,4,5,7,9 from the list.  If the second number in a range is\r
350    omitted, all remaining patches are taken.  E.g. "7-" to choose\r
351    7,8,9 from the list.  You can say <emphasis>*</emphasis> to choose everything.\r
352 </simpara>\r
353 <simpara>What you chose are then highlighted with <emphasis>*</emphasis>,\r
354 like this:</simpara>\r
355 <screen>           staged     unstaged path\r
356   1:       binary      nothing foo.png\r
357 * 2:     +403/-35        +1/-1 git-add--interactive.perl</screen>\r
358 <simpara>To remove selection, prefix the input with <emphasis>-</emphasis>\r
359 like this:</simpara>\r
360 <screen>Update&gt;&gt; -2</screen>\r
361 <simpara>After making the selection, answer with an empty line to stage the\r
362 contents of working tree files for selected paths in the index.</simpara>\r
363 </listitem>\r
364 </varlistentry>\r
365 <varlistentry>\r
366 <term>\r
367 revert\r
368 </term>\r
369 <listitem>\r
370 <simpara>\r
371   This has a very similar UI to <emphasis>update</emphasis>, and the staged\r
372   information for selected paths are reverted to that of the\r
373   HEAD version.  Reverting new paths makes them untracked.\r
374 </simpara>\r
375 </listitem>\r
376 </varlistentry>\r
377 <varlistentry>\r
378 <term>\r
379 add untracked\r
380 </term>\r
381 <listitem>\r
382 <simpara>\r
383   This has a very similar UI to <emphasis>update</emphasis> and\r
384   <emphasis>revert</emphasis>, and lets you add untracked paths to the index.\r
385 </simpara>\r
386 </listitem>\r
387 </varlistentry>\r
388 <varlistentry>\r
389 <term>\r
390 patch\r
391 </term>\r
392 <listitem>\r
393 <simpara>\r
394   This lets you choose one path out of a <emphasis>status</emphasis> like selection.\r
395   After choosing the path, it presents the diff between the index\r
396   and the working tree file and asks you if you want to stage\r
397   the change of each hunk.  You can select one of the following\r
398   options and type return:\r
399 </simpara>\r
400 <literallayout class="monospaced">y - stage this hunk\r
401 n - do not stage this hunk\r
402 q - quit; do not stage this hunk nor any of the remaining ones\r
403 a - stage this hunk and all later hunks in the file\r
404 d - do not stage this hunk nor any of the later hunks in the file\r
405 g - select a hunk to go to\r
406 / - search for a hunk matching the given regex\r
407 j - leave this hunk undecided, see next undecided hunk\r
408 J - leave this hunk undecided, see next hunk\r
409 k - leave this hunk undecided, see previous undecided hunk\r
410 K - leave this hunk undecided, see previous hunk\r
411 s - split the current hunk into smaller hunks\r
412 e - manually edit the current hunk\r
413 ? - print help</literallayout>\r
414 <simpara>After deciding the fate for all hunks, if there is any hunk\r
415 that was chosen, the index is updated with the selected hunks.</simpara>\r
416 <simpara>You can omit having to type return here, by setting the configuration\r
417 variable <emphasis>interactive.singlekey</emphasis> to <emphasis>true</emphasis>.</simpara>\r
418 </listitem>\r
419 </varlistentry>\r
420 <varlistentry>\r
421 <term>\r
422 diff\r
423 </term>\r
424 <listitem>\r
425 <simpara>\r
426   This lets you review what will be committed (i.e. between\r
427   HEAD and index).\r
428 </simpara>\r
429 </listitem>\r
430 </varlistentry>\r
431 </variablelist>\r
432 </simplesect>\r
433 <simplesect id="git-add(1)__editing_patches">\r
434 <title>EDITING PATCHES</title>\r
435 <simpara>Invoking <emphasis>git add -e</emphasis> or selecting <emphasis>e</emphasis> from the interactive hunk\r
436 selector will open a patch in your editor; after the editor exits, the\r
437 result is applied to the index. You are free to make arbitrary changes\r
438 to the patch, but note that some changes may have confusing results, or\r
439 even result in a patch that cannot be applied.  If you want to abort the\r
440 operation entirely (i.e., stage nothing new in the index), simply delete\r
441 all lines of the patch. The list below describes some common things you\r
442 may see in a patch, and which editing operations make sense on them.</simpara>\r
443 <variablelist>\r
444 <varlistentry>\r
445 <term>\r
446 added content\r
447 </term>\r
448 <listitem>\r
449 <simpara>\r
450 Added content is represented by lines beginning with "&#43;". You can\r
451 prevent staging any addition lines by deleting them.\r
452 </simpara>\r
453 </listitem>\r
454 </varlistentry>\r
455 <varlistentry>\r
456 <term>\r
457 removed content\r
458 </term>\r
459 <listitem>\r
460 <simpara>\r
461 Removed content is represented by lines beginning with "-". You can\r
462 prevent staging their removal by converting the "-" to a " " (space).\r
463 </simpara>\r
464 </listitem>\r
465 </varlistentry>\r
466 <varlistentry>\r
467 <term>\r
468 modified content\r
469 </term>\r
470 <listitem>\r
471 <simpara>\r
472 Modified content is represented by "-" lines (removing the old content)\r
473 followed by "&#43;" lines (adding the replacement content). You can\r
474 prevent staging the modification by converting "-" lines to " ", and\r
475 removing "&#43;" lines. Beware that modifying only half of the pair is\r
476 likely to introduce confusing changes to the index.\r
477 </simpara>\r
478 </listitem>\r
479 </varlistentry>\r
480 </variablelist>\r
481 <simpara>There are also more complex operations that can be performed. But beware\r
482 that because the patch is applied only to the index and not the working\r
483 tree, the working tree will appear to "undo" the change in the index.\r
484 For example, introducing a new line into the index that is in neither\r
485 the HEAD nor the working tree will stage the new line for commit, but\r
486 the line will appear to be reverted in the working tree.</simpara>\r
487 <simpara>Avoid using these constructs, or do so with extreme caution.</simpara>\r
488 <variablelist>\r
489 <varlistentry>\r
490 <term>\r
491 removing untouched content\r
492 </term>\r
493 <listitem>\r
494 <simpara>\r
495 Content which does not differ between the index and working tree may be\r
496 shown on context lines, beginning with a " " (space).  You can stage\r
497 context lines for removal by converting the space to a "-". The\r
498 resulting working tree file will appear to re-add the content.\r
499 </simpara>\r
500 </listitem>\r
501 </varlistentry>\r
502 <varlistentry>\r
503 <term>\r
504 modifying existing content\r
505 </term>\r
506 <listitem>\r
507 <simpara>\r
508 One can also modify context lines by staging them for removal (by\r
509 converting " " to "-") and adding a "&#43;" line with the new content.\r
510 Similarly, one can modify "&#43;" lines for existing additions or\r
511 modifications. In all cases, the new modification will appear reverted\r
512 in the working tree.\r
513 </simpara>\r
514 </listitem>\r
515 </varlistentry>\r
516 <varlistentry>\r
517 <term>\r
518 new content\r
519 </term>\r
520 <listitem>\r
521 <simpara>\r
522 You may also add new content that does not exist in the patch; simply\r
523 add new lines, each starting with "&#43;". The addition will appear\r
524 reverted in the working tree.\r
525 </simpara>\r
526 </listitem>\r
527 </varlistentry>\r
528 </variablelist>\r
529 <simpara>There are also several operations which should be avoided entirely, as\r
530 they will make the patch impossible to apply:</simpara>\r
531 <itemizedlist>\r
532 <listitem>\r
533 <simpara>\r
534 adding context (" ") or removal ("-") lines\r
535 </simpara>\r
536 </listitem>\r
537 <listitem>\r
538 <simpara>\r
539 deleting context or removal lines\r
540 </simpara>\r
541 </listitem>\r
542 <listitem>\r
543 <simpara>\r
544 modifying the contents of context or removal lines\r
545 </simpara>\r
546 </listitem>\r
547 </itemizedlist>\r
548 </simplesect>\r
549 <simplesect id="git-add(1)__see_also">\r
550 <title>SEE ALSO</title>\r
551 <simpara><xref linkend="git-status(1)" />\r
552 <xref linkend="git-rm(1)" />\r
553 <xref linkend="git-reset(1)" />\r
554 <xref linkend="git-mv(1)" />\r
555 <xref linkend="git-commit(1)" />\r
556 <xref linkend="git-update-index(1)" /></simpara>\r
557 </simplesect>\r
558 <simplesect id="git-add(1)__git">\r
559 <title>GIT</title>\r
560 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
561 </simplesect>\r
562 </sect2>\r