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