blob: 8637be6ab9683bcfcda6e8f1cf11084ab924200c [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231<!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" />
Junio C Hamano7e9f6b72006-02-22 10:44:556<meta name="generator" content="AsciiDoc 7.0.2" />
Junio C Hamano1a4e8412005-12-27 08:17:237<style type="text/css">
8/* Debug borders */
9p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
10/*
11 border: 1px solid red;
12*/
13}
14
15body {
16 margin: 1em 5% 1em 5%;
17}
18
19a { color: blue; }
20a:visited { color: fuchsia; }
21
22em {
23 font-style: italic;
24}
25
26strong {
27 font-weight: bold;
28}
29
30tt {
31 color: navy;
32}
33
34h1, h2, h3, h4, h5, h6 {
35 color: #527bbd;
36 font-family: sans-serif;
37 margin-top: 1.2em;
38 margin-bottom: 0.5em;
39 line-height: 1.3;
40}
41
42h1 {
43 border-bottom: 2px solid silver;
44}
45h2 {
46 border-bottom: 2px solid silver;
47 padding-top: 0.5em;
48}
49
50div.sectionbody {
51 font-family: serif;
52 margin-left: 0;
53}
54
55hr {
56 border: 1px solid silver;
57}
58
59p {
60 margin-top: 0.5em;
61 margin-bottom: 0.5em;
62}
63
64pre {
65 padding: 0;
66 margin: 0;
67}
68
69span#author {
70 color: #527bbd;
71 font-family: sans-serif;
72 font-weight: bold;
73 font-size: 1.2em;
74}
75span#email {
76}
77span#revision {
78 font-family: sans-serif;
79}
80
81div#footer {
82 font-family: sans-serif;
83 font-size: small;
84 border-top: 2px solid silver;
85 padding-top: 0.5em;
86 margin-top: 4.0em;
87}
88div#footer-text {
89 float: left;
90 padding-bottom: 0.5em;
91}
92div#footer-badges {
93 float: right;
94 padding-bottom: 0.5em;
95}
96
97div#preamble,
98div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
99div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
100div.admonitionblock {
101 margin-right: 10%;
102 margin-top: 1.5em;
103 margin-bottom: 1.5em;
104}
105div.admonitionblock {
106 margin-top: 2.5em;
107 margin-bottom: 2.5em;
108}
109
110div.content { /* Block element content. */
111 padding: 0;
112}
113
114/* Block element titles. */
115div.title, caption.title {
116 font-family: sans-serif;
117 font-weight: bold;
118 text-align: left;
119 margin-top: 1.0em;
120 margin-bottom: 0.5em;
121}
122div.title + * {
123 margin-top: 0;
124}
125
126td div.title:first-child {
127 margin-top: 0.0em;
128}
129div.content div.title:first-child {
130 margin-top: 0.0em;
131}
132div.content + div.title {
133 margin-top: 0.0em;
134}
135
136div.sidebarblock > div.content {
137 background: #ffffee;
138 border: 1px solid silver;
139 padding: 0.5em;
140}
141
142div.listingblock > div.content {
143 border: 1px solid silver;
144 background: #f4f4f4;
145 padding: 0.5em;
146}
147
148div.quoteblock > div.content {
149 padding-left: 2.0em;
150}
151div.quoteblock .attribution {
152 text-align: right;
153}
154
155div.admonitionblock .icon {
156 vertical-align: top;
157 font-size: 1.1em;
158 font-weight: bold;
159 text-decoration: underline;
160 color: #527bbd;
161 padding-right: 0.5em;
162}
163div.admonitionblock td.content {
164 padding-left: 0.5em;
165 border-left: 2px solid silver;
166}
167
168div.exampleblock > div.content {
169 border-left: 2px solid silver;
170 padding: 0.5em;
171}
172
173div.verseblock div.content {
174 white-space: pre;
175}
176
177div.imageblock div.content { padding-left: 0; }
178div.imageblock img { border: 1px solid silver; }
179span.image img { border-style: none; }
180
181dl {
182 margin-top: 0.8em;
183 margin-bottom: 0.8em;
184}
185dt {
186 margin-top: 0.5em;
187 margin-bottom: 0;
188 font-style: italic;
189}
190dd > *:first-child {
191 margin-top: 0;
192}
193
194ul, ol {
195 list-style-position: outside;
196}
197ol.olist2 {
198 list-style-type: lower-alpha;
199}
200
201div.tableblock > table {
202 border-color: #527bbd;
203 border-width: 3px;
204}
205thead {
206 font-family: sans-serif;
207 font-weight: bold;
208}
209tfoot {
210 font-weight: bold;
211}
212
213div.hlist {
214 margin-top: 0.8em;
215 margin-bottom: 0.8em;
216}
217td.hlist1 {
218 vertical-align: top;
219 font-style: italic;
220 padding-right: 0.8em;
221}
222td.hlist2 {
223 vertical-align: top;
224}
225
226@media print {
227 div#footer-badges { display: none; }
228}
229include::./stylesheets/xhtml11-manpage.css[]
230/* Workarounds for IE6's broken and incomplete CSS2. */
231
232div.sidebar-content {
233 background: #ffffee;
234 border: 1px solid silver;
235 padding: 0.5em;
236}
237div.sidebar-title, div.image-title {
238 font-family: sans-serif;
239 font-weight: bold;
240 margin-top: 0.0em;
241 margin-bottom: 0.5em;
242}
243
244div.listingblock div.content {
245 border: 1px solid silver;
246 background: #f4f4f4;
247 padding: 0.5em;
248}
249
250div.quoteblock-content {
251 padding-left: 2.0em;
252}
253
254div.exampleblock-content {
255 border-left: 2px solid silver;
256 padding-left: 0.5em;
257}
258</style>
259<title>git-add(1)</title>
260</head>
261<body>
262<div id="header">
263<h1>
264git-add(1) Manual Page
265</h1>
266<h2>NAME</h2>
267<div class="sectionbody">
268<p>git-add -
Junio C Hamano4cd1c0e2007-08-06 04:39:14269 Add file contents to the index
Junio C Hamano1a4e8412005-12-27 08:17:23270</p>
271</div>
272</div>
273<h2>SYNOPSIS</h2>
274<div class="sectionbody">
Junio C Hamano024b6c62007-08-14 09:43:08275<p><em>git-add</em> [-n] [-v] [-f] [--interactive | -i] [-u] [--refresh] [--] &lt;file&gt;&#8230;</p>
Junio C Hamano1a4e8412005-12-27 08:17:23276</div>
277<h2>DESCRIPTION</h2>
278<div class="sectionbody">
Junio C Hamano4cd1c0e2007-08-06 04:39:14279<p>This command adds the current content of new or modified files to the
280index, thus staging that content for inclusion in the next commit.</p>
281<p>The "index" holds a snapshot of the content of the working tree, and it
282is this snapshot that is taken as the contents of the next commit. Thus
283after making any changes to the working directory, and before running
284the commit command, you must use the <em>add</em> command to add any new or
285modified files to the index.</p>
286<p>This command can be performed multiple times before a commit. It only
287adds the content of the specified file(s) at the time the add command is
288run; if you want subsequent changes included in the next commit, then
289you must run <em>git add</em> again to add the new content to the index.</p>
290<p>The <em>git status</em> command can be used to obtain a summary of which
291files have changes that are staged for the next commit.</p>
Junio C Hamano3c1f2c72007-08-17 07:48:05292<p>The <em>git add</em> command will not add ignored files by default. If any
293ignored files were explicitly specified on the command line, <em>git add</em>
294will fail with a list of ignored files. Ignored files reached by
295directory recursion or filename globbing will be silently ignored.
296The <em>add</em> command can be used to add ignored files with the <tt>-f</tt>
297(force) option.</p>
Junio C Hamanoe7935c42006-12-13 21:32:17298<p>Please see <a href="git-commit.html">git-commit(1)</a> for alternative ways to add content to a
299commit.</p>
Junio C Hamano1a4e8412005-12-27 08:17:23300</div>
301<h2>OPTIONS</h2>
302<div class="sectionbody">
303<dl>
304<dt>
305&lt;file&gt;&#8230;
306</dt>
307<dd>
308<p>
Junio C Hamano3d2adc72006-12-26 03:21:45309 Files to add content from. Fileglobs (e.g. <tt>*.c</tt>) can
310 be given to add all matching files. Also a
311 leading directory name (e.g. <tt>dir</tt> to add <tt>dir/file1</tt>
312 and <tt>dir/file2</tt>) can be given to add all files in the
313 directory, recursively.
Junio C Hamano1a4e8412005-12-27 08:17:23314</p>
315</dd>
316<dt>
317-n
318</dt>
319<dd>
320<p>
321 Don't actually add the file(s), just show if they exist.
322</p>
323</dd>
324<dt>
325-v
326</dt>
327<dd>
328<p>
329 Be verbose.
330</p>
331</dd>
Junio C Hamano7e9f6b72006-02-22 10:44:55332<dt>
Junio C Hamano3d2adc72006-12-26 03:21:45333-f
334</dt>
335<dd>
336<p>
337 Allow adding otherwise ignored files.
338</p>
339</dd>
340<dt>
Junio C Hamanoa3fd83c2007-03-02 10:34:36341-i, --interactive
Junio C Hamano17bbaca2006-12-25 11:36:31342</dt>
343<dd>
344<p>
345 Add modified contents in the working tree interactively to
346 the index.
347</p>
348</dd>
349<dt>
Junio C Hamano3d30fd52007-05-08 00:32:53350-u
351</dt>
352<dd>
353<p>
Junio C Hamano0430e3a2007-05-15 03:13:17354 Update only files that git already knows about. This is similar
355 to what "git commit -a" does in preparation for making a commit,
356 except that the update is limited to paths specified on the
357 command line. If no paths are specified, all tracked files are
358 updated.
Junio C Hamano3d30fd52007-05-08 00:32:53359</p>
360</dd>
361<dt>
Junio C Hamano024b6c62007-08-14 09:43:08362--refresh
363</dt>
364<dd>
365<p>
366 Don't add the file(s), but only refresh their stat()
367 information in the index.
368</p>
369</dd>
370<dt>
Junio C Hamano1bb569e2006-05-05 23:14:25371--
Junio C Hamano7e9f6b72006-02-22 10:44:55372</dt>
373<dd>
374<p>
375 This option can be used to separate command-line options from
376 the list of files, (useful when filenames might be mistaken
377 for command-line options).
378</p>
379</dd>
Junio C Hamano1a4e8412005-12-27 08:17:23380</dl>
381</div>
Junio C Hamano9fbd4f72007-05-18 15:54:37382<h2>Configuration</h2>
383<div class="sectionbody">
384<p>The optional configuration variable <em>core.excludesfile</em> indicates a path to a
385file containing patterns of file names to exclude from git-add, similar to
386$GIT_DIR/info/exclude. Patterns in the exclude file are used in addition to
387those in info/exclude. See <a href="repository-layout.html">repository layout</a>.</p>
388</div>
Junio C Hamano1a4e8412005-12-27 08:17:23389<h2>EXAMPLES</h2>
390<div class="sectionbody">
391<dl>
392<dt>
393git-add Documentation/\*.txt
394</dt>
395<dd>
396<p>
Junio C Hamanoe7935c42006-12-13 21:32:17397 Adds content from all <tt>*.txt</tt> files under <tt>Documentation</tt>
398 directory and its subdirectories.
Junio C Hamano1a4e8412005-12-27 08:17:23399</p>
400<p>Note that the asterisk <tt>*</tt> is quoted from the shell in this
401example; this lets the command to include the files from
402subdirectories of <tt>Documentation/</tt> directory.</p>
403</dd>
404<dt>
405git-add git-*.sh
406</dt>
407<dd>
408<p>
Junio C Hamanoe7935c42006-12-13 21:32:17409 Considers adding content from all git-*.sh scripts.
Junio C Hamano1a4e8412005-12-27 08:17:23410 Because this example lets shell expand the asterisk
411 (i.e. you are listing the files explicitly), it does not
Junio C Hamanoe7935c42006-12-13 21:32:17412 consider <tt>subdir/git-foo.sh</tt>.
Junio C Hamano1a4e8412005-12-27 08:17:23413</p>
414</dd>
415</dl>
416</div>
Junio C Hamano17bbaca2006-12-25 11:36:31417<h2>Interactive mode</h2>
418<div class="sectionbody">
419<p>When the command enters the interactive mode, it shows the
Junio C Hamanof9771f62007-01-17 17:42:30420output of the <em>status</em> subcommand, and then goes into its
Junio C Hamano17bbaca2006-12-25 11:36:31421interactive command loop.</p>
422<p>The command loop shows the list of subcommands available, and
423gives a prompt "What now&gt; ". In general, when the prompt ends
424with a single <em>&gt;</em>, you can pick only one of the choices given
425and type return, like this:</p>
426<div class="listingblock">
427<div class="content">
428<pre><tt> *** Commands ***
429 1: status 2: update 3: revert 4: add untracked
430 5: patch 6: diff 7: quit 8: help
431 What now&gt; 1</tt></pre>
432</div></div>
433<p>You also could say "s" or "sta" or "status" above as long as the
434choice is unique.</p>
435<p>The main command loop has 6 subcommands (plus help and quit).</p>
436<dl>
437<dt>
438status
439</dt>
440<dd>
441<p>
442 This shows the change between HEAD and index (i.e. what will be
443 committed if you say "git commit"), and between index and
444 working tree files (i.e. what you could stage further before
445 "git commit" using "git-add") for each path. A sample output
446 looks like this:
447</p>
448<div class="listingblock">
449<div class="content">
450<pre><tt> staged unstaged path
451 1: binary nothing foo.png
452 2: +403/-35 +1/-1 git-add--interactive.perl</tt></pre>
453</div></div>
454<p>It shows that foo.png has differences from HEAD (but that is
455binary so line count cannot be shown) and there is no
456difference between indexed copy and the working tree
457version (if the working tree version were also different,
458<em>binary</em> would have been shown in place of <em>nothing</em>). The
459other file, git-add--interactive.perl, has 403 lines added
460and 35 lines deleted if you commit what is in the index, but
461working tree file has further modifications (one addition and
462one deletion).</p>
463</dd>
464<dt>
465update
466</dt>
467<dd>
468<p>
469 This shows the status information and gives prompt
470 "Update&gt;&gt;". When the prompt ends with double <em>&gt;&gt;</em>, you can
471 make more than one selection, concatenated with whitespace or
472 comma. Also you can say ranges. E.g. "2-5 7,9" to choose
473 2,3,4,5,7,9 from the list. You can say <em>*</em> to choose
474 everything.
475</p>
476<p>What you chose are then highlighted with <em>*</em>,
477like this:</p>
478<div class="listingblock">
479<div class="content">
480<pre><tt> staged unstaged path
481 1: binary nothing foo.png
482* 2: +403/-35 +1/-1 git-add--interactive.perl</tt></pre>
483</div></div>
484<p>To remove selection, prefix the input with <tt>-</tt>
485like this:</p>
486<div class="listingblock">
487<div class="content">
488<pre><tt>Update&gt;&gt; -2</tt></pre>
489</div></div>
490<p>After making the selection, answer with an empty line to stage the
491contents of working tree files for selected paths in the index.</p>
492</dd>
493<dt>
494revert
495</dt>
496<dd>
497<p>
498 This has a very similar UI to <em>update</em>, and the staged
499 information for selected paths are reverted to that of the
500 HEAD version. Reverting new paths makes them untracked.
501</p>
502</dd>
503<dt>
504add untracked
505</dt>
506<dd>
507<p>
508 This has a very similar UI to <em>update</em> and
509 <em>revert</em>, and lets you add untracked paths to the index.
510</p>
511</dd>
512<dt>
513patch
514</dt>
515<dd>
516<p>
517 This lets you choose one path out of <em>status</em> like selection.
518 After choosing the path, it presents diff between the index
519 and the working tree file and asks you if you want to stage
520 the change of each hunk. You can say:
521</p>
522<div class="literalblock">
523<div class="content">
524<pre><tt>y - add the change from that hunk to index
525n - do not add the change from that hunk to index
526a - add the change from that hunk and all the rest to index
527d - do not the change from that hunk nor any of the rest to index
528j - do not decide on this hunk now, and view the next
529 undecided hunk
530J - do not decide on this hunk now, and view the next hunk
531k - do not decide on this hunk now, and view the previous
532 undecided hunk
533K - do not decide on this hunk now, and view the previous hunk</tt></pre>
534</div></div>
535<p>After deciding the fate for all hunks, if there is any hunk
536that was chosen, the index is updated with the selected hunks.</p>
537</dd>
538<dt>
539diff
540</dt>
541<dd>
542<p>
543 This lets you review what will be committed (i.e. between
544 HEAD and index).
545</p>
546</dd>
547</dl>
548</div>
Junio C Hamano2bb13102006-03-06 07:10:21549<h2>See Also</h2>
550<div class="sectionbody">
Junio C Hamanoe7935c42006-12-13 21:32:17551<p><a href="git-status.html">git-status(1)</a>
552<a href="git-rm.html">git-rm(1)</a>
553<a href="git-mv.html">git-mv(1)</a>
554<a href="git-commit.html">git-commit(1)</a>
555<a href="git-update-index.html">git-update-index(1)</a></p>
Junio C Hamano2bb13102006-03-06 07:10:21556</div>
Junio C Hamano1a4e8412005-12-27 08:17:23557<h2>Author</h2>
558<div class="sectionbody">
559<p>Written by Linus Torvalds &lt;torvalds@osdl.org&gt;</p>
560</div>
561<h2>Documentation</h2>
562<div class="sectionbody">
563<p>Documentation by Junio C Hamano and the git-list &lt;git@vger.kernel.org&gt;.</p>
564</div>
565<h2>GIT</h2>
566<div class="sectionbody">
567<p>Part of the <a href="git.html">git(7)</a> suite</p>
568</div>
569<div id="footer">
570<div id="footer-text">
Junio C Hamano3c1f2c72007-08-17 07:48:05571Last updated 17-Aug-2007 07:47:32 UTC
Junio C Hamano1a4e8412005-12-27 08:17:23572</div>
573</div>
574</body>
575</html>