blob: e6cbd327802af4a488af391efdf646bd72626a34 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 7.0.2" />
<style type="text/css">
/* Debug borders */
p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
/*
border: 1px solid red;
*/
}
body {
margin: 1em 5% 1em 5%;
}
a { color: blue; }
a:visited { color: fuchsia; }
em {
font-style: italic;
}
strong {
font-weight: bold;
}
tt {
color: navy;
}
h1, h2, h3, h4, h5, h6 {
color: #527bbd;
font-family: sans-serif;
margin-top: 1.2em;
margin-bottom: 0.5em;
line-height: 1.3;
}
h1 {
border-bottom: 2px solid silver;
}
h2 {
border-bottom: 2px solid silver;
padding-top: 0.5em;
}
div.sectionbody {
font-family: serif;
margin-left: 0;
}
hr {
border: 1px solid silver;
}
p {
margin-top: 0.5em;
margin-bottom: 0.5em;
}
pre {
padding: 0;
margin: 0;
}
span#author {
color: #527bbd;
font-family: sans-serif;
font-weight: bold;
font-size: 1.2em;
}
span#email {
}
span#revision {
font-family: sans-serif;
}
div#footer {
font-family: sans-serif;
font-size: small;
border-top: 2px solid silver;
padding-top: 0.5em;
margin-top: 4.0em;
}
div#footer-text {
float: left;
padding-bottom: 0.5em;
}
div#footer-badges {
float: right;
padding-bottom: 0.5em;
}
div#preamble,
div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
div.admonitionblock {
margin-right: 10%;
margin-top: 1.5em;
margin-bottom: 1.5em;
}
div.admonitionblock {
margin-top: 2.5em;
margin-bottom: 2.5em;
}
div.content { /* Block element content. */
padding: 0;
}
/* Block element titles. */
div.title, caption.title {
font-family: sans-serif;
font-weight: bold;
text-align: left;
margin-top: 1.0em;
margin-bottom: 0.5em;
}
div.title + * {
margin-top: 0;
}
td div.title:first-child {
margin-top: 0.0em;
}
div.content div.title:first-child {
margin-top: 0.0em;
}
div.content + div.title {
margin-top: 0.0em;
}
div.sidebarblock > div.content {
background: #ffffee;
border: 1px solid silver;
padding: 0.5em;
}
div.listingblock > div.content {
border: 1px solid silver;
background: #f4f4f4;
padding: 0.5em;
}
div.quoteblock > div.content {
padding-left: 2.0em;
}
div.quoteblock .attribution {
text-align: right;
}
div.admonitionblock .icon {
vertical-align: top;
font-size: 1.1em;
font-weight: bold;
text-decoration: underline;
color: #527bbd;
padding-right: 0.5em;
}
div.admonitionblock td.content {
padding-left: 0.5em;
border-left: 2px solid silver;
}
div.exampleblock > div.content {
border-left: 2px solid silver;
padding: 0.5em;
}
div.verseblock div.content {
white-space: pre;
}
div.imageblock div.content { padding-left: 0; }
div.imageblock img { border: 1px solid silver; }
span.image img { border-style: none; }
dl {
margin-top: 0.8em;
margin-bottom: 0.8em;
}
dt {
margin-top: 0.5em;
margin-bottom: 0;
font-style: italic;
}
dd > *:first-child {
margin-top: 0;
}
ul, ol {
list-style-position: outside;
}
ol.olist2 {
list-style-type: lower-alpha;
}
div.tableblock > table {
border-color: #527bbd;
border-width: 3px;
}
thead {
font-family: sans-serif;
font-weight: bold;
}
tfoot {
font-weight: bold;
}
div.hlist {
margin-top: 0.8em;
margin-bottom: 0.8em;
}
td.hlist1 {
vertical-align: top;
font-style: italic;
padding-right: 0.8em;
}
td.hlist2 {
vertical-align: top;
}
@media print {
div#footer-badges { display: none; }
}
include::./stylesheets/xhtml11-manpage.css[]
/* Workarounds for IE6's broken and incomplete CSS2. */
div.sidebar-content {
background: #ffffee;
border: 1px solid silver;
padding: 0.5em;
}
div.sidebar-title, div.image-title {
font-family: sans-serif;
font-weight: bold;
margin-top: 0.0em;
margin-bottom: 0.5em;
}
div.listingblock div.content {
border: 1px solid silver;
background: #f4f4f4;
padding: 0.5em;
}
div.quoteblock-content {
padding-left: 2.0em;
}
div.exampleblock-content {
border-left: 2px solid silver;
padding-left: 0.5em;
}
</style>
<title>git-add(1)</title>
</head>
<body>
<div id="header">
<h1>
git-add(1) Manual Page
</h1>
<h2>NAME</h2>
<div class="sectionbody">
<p>git-add -
Add file contents to the changeset to be committed next
</p>
</div>
</div>
<h2>SYNOPSIS</h2>
<div class="sectionbody">
<p><em>git-add</em> [-n] [-v] [-f] [--interactive | -i] [--] &lt;file&gt;&#8230;</p>
</div>
<h2>DESCRIPTION</h2>
<div class="sectionbody">
<p>All the changed file contents to be committed together in a single set
of changes must be "added" with the <em>add</em> command before using the
<em>commit</em> command. This is not only for adding new files. Even modified
files must be added to the set of changes about to be committed.</p>
<p>This command can be performed multiple times before a commit. The added
content corresponds to the state of specified file(s) at the time the
<em>add</em> command is used. This means the <em>commit</em> command will not consider
subsequent changes to already added content if it is not added again before
the commit.</p>
<p>The <em>git status</em> command can be used to obtain a summary of what is included
for the next commit.</p>
<p>This command can be used to add ignored files with <tt>-f</tt> (force)
option, but they have to be
explicitly and exactly specified from the command line. File globbing
and recursive behaviour do not add ignored files.</p>
<p>Please see <a href="git-commit.html">git-commit(1)</a> for alternative ways to add content to a
commit.</p>
</div>
<h2>OPTIONS</h2>
<div class="sectionbody">
<dl>
<dt>
&lt;file&gt;&#8230;
</dt>
<dd>
<p>
Files to add content from. Fileglobs (e.g. <tt>*.c</tt>) can
be given to add all matching files. Also a
leading directory name (e.g. <tt>dir</tt> to add <tt>dir/file1</tt>
and <tt>dir/file2</tt>) can be given to add all files in the
directory, recursively.
</p>
</dd>
<dt>
-n
</dt>
<dd>
<p>
Don't actually add the file(s), just show if they exist.
</p>
</dd>
<dt>
-v
</dt>
<dd>
<p>
Be verbose.
</p>
</dd>
<dt>
-f
</dt>
<dd>
<p>
Allow adding otherwise ignored files.
</p>
</dd>
<dt>
-i, --interactive
</dt>
<dd>
<p>
Add modified contents in the working tree interactively to
the index.
</p>
</dd>
<dt>
--
</dt>
<dd>
<p>
This option can be used to separate command-line options from
the list of files, (useful when filenames might be mistaken
for command-line options).
</p>
</dd>
</dl>
</div>
<h2>EXAMPLES</h2>
<div class="sectionbody">
<dl>
<dt>
git-add Documentation/\*.txt
</dt>
<dd>
<p>
Adds content from all <tt>*.txt</tt> files under <tt>Documentation</tt>
directory and its subdirectories.
</p>
<p>Note that the asterisk <tt>*</tt> is quoted from the shell in this
example; this lets the command to include the files from
subdirectories of <tt>Documentation/</tt> directory.</p>
</dd>
<dt>
git-add git-*.sh
</dt>
<dd>
<p>
Considers adding content from all git-*.sh scripts.
Because this example lets shell expand the asterisk
(i.e. you are listing the files explicitly), it does not
consider <tt>subdir/git-foo.sh</tt>.
</p>
</dd>
</dl>
</div>
<h2>Interactive mode</h2>
<div class="sectionbody">
<p>When the command enters the interactive mode, it shows the
output of the <em>status</em> subcommand, and then goes into its
interactive command loop.</p>
<p>The command loop shows the list of subcommands available, and
gives a prompt "What now&gt; ". In general, when the prompt ends
with a single <em>&gt;</em>, you can pick only one of the choices given
and type return, like this:</p>
<div class="listingblock">
<div class="content">
<pre><tt> *** Commands ***
1: status 2: update 3: revert 4: add untracked
5: patch 6: diff 7: quit 8: help
What now&gt; 1</tt></pre>
</div></div>
<p>You also could say "s" or "sta" or "status" above as long as the
choice is unique.</p>
<p>The main command loop has 6 subcommands (plus help and quit).</p>
<dl>
<dt>
status
</dt>
<dd>
<p>
This shows the change between HEAD and index (i.e. what will be
committed if you say "git commit"), and between index and
working tree files (i.e. what you could stage further before
"git commit" using "git-add") for each path. A sample output
looks like this:
</p>
<div class="listingblock">
<div class="content">
<pre><tt> staged unstaged path
1: binary nothing foo.png
2: +403/-35 +1/-1 git-add--interactive.perl</tt></pre>
</div></div>
<p>It shows that foo.png has differences from HEAD (but that is
binary so line count cannot be shown) and there is no
difference between indexed copy and the working tree
version (if the working tree version were also different,
<em>binary</em> would have been shown in place of <em>nothing</em>). The
other file, git-add--interactive.perl, has 403 lines added
and 35 lines deleted if you commit what is in the index, but
working tree file has further modifications (one addition and
one deletion).</p>
</dd>
<dt>
update
</dt>
<dd>
<p>
This shows the status information and gives prompt
"Update&gt;&gt;". When the prompt ends with double <em>&gt;&gt;</em>, you can
make more than one selection, concatenated with whitespace or
comma. Also you can say ranges. E.g. "2-5 7,9" to choose
2,3,4,5,7,9 from the list. You can say <em>*</em> to choose
everything.
</p>
<p>What you chose are then highlighted with <em>*</em>,
like this:</p>
<div class="listingblock">
<div class="content">
<pre><tt> staged unstaged path
1: binary nothing foo.png
* 2: +403/-35 +1/-1 git-add--interactive.perl</tt></pre>
</div></div>
<p>To remove selection, prefix the input with <tt>-</tt>
like this:</p>
<div class="listingblock">
<div class="content">
<pre><tt>Update&gt;&gt; -2</tt></pre>
</div></div>
<p>After making the selection, answer with an empty line to stage the
contents of working tree files for selected paths in the index.</p>
</dd>
<dt>
revert
</dt>
<dd>
<p>
This has a very similar UI to <em>update</em>, and the staged
information for selected paths are reverted to that of the
HEAD version. Reverting new paths makes them untracked.
</p>
</dd>
<dt>
add untracked
</dt>
<dd>
<p>
This has a very similar UI to <em>update</em> and
<em>revert</em>, and lets you add untracked paths to the index.
</p>
</dd>
<dt>
patch
</dt>
<dd>
<p>
This lets you choose one path out of <em>status</em> like selection.
After choosing the path, it presents diff between the index
and the working tree file and asks you if you want to stage
the change of each hunk. You can say:
</p>
<div class="literalblock">
<div class="content">
<pre><tt>y - add the change from that hunk to index
n - do not add the change from that hunk to index
a - add the change from that hunk and all the rest to index
d - do not the change from that hunk nor any of the rest to index
j - do not decide on this hunk now, and view the next
undecided hunk
J - do not decide on this hunk now, and view the next hunk
k - do not decide on this hunk now, and view the previous
undecided hunk
K - do not decide on this hunk now, and view the previous hunk</tt></pre>
</div></div>
<p>After deciding the fate for all hunks, if there is any hunk
that was chosen, the index is updated with the selected hunks.</p>
</dd>
<dt>
diff
</dt>
<dd>
<p>
This lets you review what will be committed (i.e. between
HEAD and index).
</p>
</dd>
</dl>
</div>
<h2>See Also</h2>
<div class="sectionbody">
<p><a href="git-status.html">git-status(1)</a>
<a href="git-rm.html">git-rm(1)</a>
<a href="git-mv.html">git-mv(1)</a>
<a href="git-commit.html">git-commit(1)</a>
<a href="git-update-index.html">git-update-index(1)</a></p>
</div>
<h2>Author</h2>
<div class="sectionbody">
<p>Written by Linus Torvalds &lt;torvalds@osdl.org&gt;</p>
</div>
<h2>Documentation</h2>
<div class="sectionbody">
<p>Documentation by Junio C Hamano and the git-list &lt;git@vger.kernel.org&gt;.</p>
</div>
<h2>GIT</h2>
<div class="sectionbody">
<p>Part of the <a href="git.html">git(7)</a> suite</p>
</div>
<div id="footer">
<div id="footer-text">
Last updated 04-Apr-2007 18:33:21 UTC
</div>
</div>
</body>
</html>