1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
\r
4 <article lang="en" id="git-add(1)">
\r
6 <title>git-add(1)</title>
\r
8 <primary>git-add(1)</primary>
\r
11 <simplesect id="_name">
\r
13 <simpara>git-add - Add file contents to the index</simpara>
\r
15 <simplesect id="_synopsis">
\r
16 <title>SYNOPSIS</title>
\r
18 <literallayout><emphasis>git add</emphasis> [-n] [-v] [--force | -f] [--interactive | -i] [--patch | -p]
\r
19 [--all | [--update | -u]] [--intent-to-add | -N]
\r
20 [--refresh] [--ignore-errors] [--] <filepattern>…</literallayout>
\r
23 <simplesect id="_description">
\r
24 <title>DESCRIPTION</title>
\r
25 <simpara>This command adds the current content of new or modified files to the
\r
26 index, thus staging that content for inclusion in the next commit.</simpara>
\r
27 <simpara>The "index" holds a snapshot of the content of the working tree, and it
\r
28 is this snapshot that is taken as the contents of the next commit. Thus
\r
29 after making any changes to the working directory, and before running
\r
30 the commit command, you must use the <emphasis>add</emphasis> command to add any new or
\r
31 modified files to the index.</simpara>
\r
32 <simpara>This command can be performed multiple times before a commit. It only
\r
33 adds the content of the specified file(s) at the time the add command is
\r
34 run; if you want subsequent changes included in the next commit, then
\r
35 you must run <emphasis>git add</emphasis> again to add the new content to the index.</simpara>
\r
36 <simpara>The <emphasis>git status</emphasis> command can be used to obtain a summary of which
\r
37 files have changes that are staged for the next commit.</simpara>
\r
38 <simpara>The <emphasis>git add</emphasis> command will not add ignored files by default. If any
\r
39 ignored files were explicitly specified on the command line, <emphasis>git add</emphasis>
\r
40 will fail with a list of ignored files. Ignored files reached by
\r
41 directory recursion or filename globbing performed by Git (quote your
\r
42 globs before the shell) will be silently ignored. The <emphasis>add</emphasis> command can
\r
43 be used to add ignored files with the <literal>-f</literal> (force) option.</simpara>
\r
44 <simpara>Please see <xref linkend="git-commit(1)"/> for alternative ways to add content to a
\r
47 <simplesect id="_options">
\r
48 <title>OPTIONS</title>
\r
52 <filepattern>…
\r
56 Files to add content from. Fileglobs (e.g. <literal>*.c</literal>) can
\r
57 be given to add all matching files. Also a
\r
58 leading directory name (e.g. <literal>dir</literal> to add <literal>dir/file1</literal>
\r
59 and <literal>dir/file2</literal>) can be given to add all files in the
\r
60 directory, recursively.
\r
73 Don’t actually add the file(s), just show if they exist.
\r
99 Allow adding otherwise ignored files.
\r
112 Add modified contents in the working tree interactively to
\r
113 the index. Optional path arguments may be supplied to limit
\r
114 operation to a subset of the working tree. See “Interactive
\r
115 mode” for details.
\r
128 Similar to Interactive mode but the initial command loop is
\r
129 bypassed and the <emphasis>patch</emphasis> subcommand is invoked using each of
\r
130 the specified filepatterns before exiting.
\r
143 Update only files that git already knows about, staging modified
\r
144 content for commit and marking deleted files for removal. This
\r
146 to what "git commit -a" does in preparation for making a commit,
\r
147 except that the update is limited to paths specified on the
\r
148 command line. If no paths are specified, all tracked files in the
\r
149 current directory and its subdirectories are updated.
\r
162 Update files that git already knows about (same as <emphasis>--update</emphasis>)
\r
163 and add all untracked files that are not ignored by <emphasis>.gitignore</emphasis>
\r
177 Record only the fact that the path will be added later. An entry
\r
178 for the path is placed in the index with no content. This is
\r
179 useful for, among other things, showing the unstaged content of
\r
180 such files with <emphasis>git diff</emphasis> and committing them with <emphasis>git commit
\r
191 Don’t add the file(s), but only refresh their stat()
\r
192 information in the index.
\r
202 If some files could not be added because of errors indexing
\r
203 them, do not abort the operation, but continue adding the
\r
204 others. The command shall still exit with non-zero status.
\r
214 This option can be used to separate command-line options from
\r
215 the list of files, (useful when filenames might be mistaken
\r
216 for command-line options).
\r
222 <simplesect id="_configuration">
\r
223 <title>Configuration</title>
\r
224 <simpara>The optional configuration variable <emphasis>core.excludesfile</emphasis> indicates a path to a
\r
225 file containing patterns of file names to exclude from git-add, similar to
\r
226 $GIT_DIR/info/exclude. Patterns in the exclude file are used in addition to
\r
227 those in info/exclude. See <xref linkend="gitrepository-layout(5)"/>.</simpara>
\r
229 <simplesect id="_examples">
\r
230 <title>EXAMPLES</title>
\r
234 Adds content from all <literal>\*.txt</literal> files under <literal>Documentation</literal> directory
\r
235 and its subdirectories:
\r
237 <literallayout>$ git add Documentation/\\*.txt</literallayout>
\r
238 <simpara>Note that the asterisk <literal>\*</literal> is quoted from the shell in this
\r
239 example; this lets the command to include the files from
\r
240 subdirectories of <literal>Documentation/</literal> directory.</simpara>
\r
244 Considers adding content from all git-*.sh scripts:
\r
246 <literallayout>$ git add git-*.sh</literallayout>
\r
247 <simpara>Because this example lets shell expand the asterisk (i.e. you are
\r
248 listing the files explicitly), it does not consider
\r
249 <literal>subdir/git-foo.sh</literal>.</simpara>
\r
253 <simplesect id="_interactive_mode">
\r
254 <title>Interactive mode</title>
\r
255 <simpara>When the command enters the interactive mode, it shows the
\r
256 output of the <emphasis>status</emphasis> subcommand, and then goes into its
\r
257 interactive command loop.</simpara>
\r
258 <simpara>The command loop shows the list of subcommands available, and
\r
259 gives a prompt "What now> ". In general, when the prompt ends
\r
260 with a single <emphasis>></emphasis>, you can pick only one of the choices given
\r
261 and type return, like this:</simpara>
\r
262 <literallayout> *** Commands ***
\r
263 1: status 2: update 3: revert 4: add untracked
\r
264 5: patch 6: diff 7: quit 8: help
\r
265 What now> 1</literallayout>
\r
266 <simpara>You also could say "s" or "sta" or "status" above as long as the
\r
267 choice is unique.</simpara>
\r
268 <simpara>The main command loop has 6 subcommands (plus help and quit).</simpara>
\r
276 This shows the change between HEAD and index (i.e. what will be
\r
277 committed if you say "git commit"), and between index and
\r
278 working tree files (i.e. what you could stage further before
\r
279 "git commit" using "git-add") for each path. A sample output
\r
282 <literallayout> staged unstaged path
\r
283 1: binary nothing foo.png
\r
284 2: +403/-35 +1/-1 git-add--interactive.perl</literallayout>
\r
285 <simpara>It shows that foo.png has differences from HEAD (but that is
\r
286 binary so line count cannot be shown) and there is no
\r
287 difference between indexed copy and the working tree
\r
288 version (if the working tree version were also different,
\r
289 <emphasis>binary</emphasis> would have been shown in place of <emphasis>nothing</emphasis>). The
\r
290 other file, git-add—interactive.perl, has 403 lines added
\r
291 and 35 lines deleted if you commit what is in the index, but
\r
292 working tree file has further modifications (one addition and
\r
293 one deletion).</simpara>
\r
302 This shows the status information and gives prompt
\r
303 "Update>>". When the prompt ends with double <emphasis>>></emphasis>, you can
\r
304 make more than one selection, concatenated with whitespace or
\r
305 comma. Also you can say ranges. E.g. "2-5 7,9" to choose
\r
306 2,3,4,5,7,9 from the list. If the second number in a range is
\r
307 omitted, all remaining patches are taken. E.g. "7-" to choose
\r
308 7,8,9 from the list. You can say <emphasis>*</emphasis> to choose everything.
\r
310 <simpara>What you chose are then highlighted with <emphasis>*</emphasis>,
\r
311 like this:</simpara>
\r
312 <literallayout> staged unstaged path
\r
313 1: binary nothing foo.png
\r
314 * 2: +403/-35 +1/-1 git-add--interactive.perl</literallayout>
\r
315 <simpara>To remove selection, prefix the input with <literal>-</literal>
\r
316 like this:</simpara>
\r
317 <literallayout>Update>> -2</literallayout>
\r
318 <simpara>After making the selection, answer with an empty line to stage the
\r
319 contents of working tree files for selected paths in the index.</simpara>
\r
328 This has a very similar UI to <emphasis>update</emphasis>, and the staged
\r
329 information for selected paths are reverted to that of the
\r
330 HEAD version. Reverting new paths makes them untracked.
\r
340 This has a very similar UI to <emphasis>update</emphasis> and
\r
341 <emphasis>revert</emphasis>, and lets you add untracked paths to the index.
\r
351 This lets you choose one path out of <emphasis>status</emphasis> like selection.
\r
352 After choosing the path, it presents diff between the index
\r
353 and the working tree file and asks you if you want to stage
\r
354 the change of each hunk. You can say:
\r
356 <literallayout class="monospaced">y - stage this hunk
\r
357 n - do not stage this hunk
\r
358 a - stage this and all the remaining hunks in the file
\r
359 d - do not stage this hunk nor any of the remaining hunks in the file
\r
360 j - leave this hunk undecided, see next undecided hunk
\r
361 J - leave this hunk undecided, see next hunk
\r
362 k - leave this hunk undecided, see previous undecided hunk
\r
363 K - leave this hunk undecided, see previous hunk
\r
364 s - split the current hunk into smaller hunks
\r
365 e - manually edit the current hunk
\r
366 ? - print help</literallayout>
\r
367 <simpara>After deciding the fate for all hunks, if there is any hunk
\r
368 that was chosen, the index is updated with the selected hunks.</simpara>
\r
377 This lets you review what will be committed (i.e. between
\r
384 <simplesect id="_bugs">
\r
385 <title>Bugs</title>
\r
386 <simpara>The interactive mode does not work with files whose names contain
\r
387 characters that need C-quoting. <literal>core.quotepath</literal> configuration can be
\r
388 used to work this limitation around to some degree, but backslash,
\r
389 double-quote and control characters will still have problems.</simpara>
\r
391 <simplesect id="_see_also">
\r
392 <title>SEE ALSO</title>
\r
393 <simpara><xref linkend="git-status(1)"/>
\r
394 <xref linkend="git-rm(1)"/>
\r
395 <xref linkend="git-reset(1)"/>
\r
396 <xref linkend="git-mv(1)"/>
\r
397 <xref linkend="git-commit(1)"/>
\r
398 <xref linkend="git-update-index(1)"/></simpara>
\r
400 <simplesect id="_author">
\r
401 <title>Author</title>
\r
402 <simpara>Written by Linus Torvalds <<ulink url="mailto:torvalds@osdl.org">torvalds@osdl.org</ulink>></simpara>
\r
404 <simplesect id="_documentation">
\r
405 <title>Documentation</title>
\r
406 <simpara>Documentation by Junio C Hamano and the git-list <<ulink url="mailto:git@vger.kernel.org">git@vger.kernel.org</ulink>>.</simpara>
\r
408 <simplesect id="_git">
\r
410 <simpara>Part of the <xref linkend="git(1)"/> suite</simpara>
\r