War on whitespace
[git/dscho.git] / Documentation / git-add.txt
blob76d2b05854ccc742105c374fae33c676795d29f1
1 git-add(1)
2 ==========
4 NAME
5 ----
6 git-add - Add file contents to the changeset to be committed next
8 SYNOPSIS
9 --------
10 'git-add' [-n] [-v] [-f] [--interactive | -i] [-u] [--] <file>...
12 DESCRIPTION
13 -----------
14 All the changed file contents to be committed together in a single set
15 of changes must be "added" with the 'add' command before using the
16 'commit' command.  This is not only for adding new files.  Even modified
17 files must be added to the set of changes about to be committed.
19 This command can be performed multiple times before a commit. The added
20 content corresponds to the state of specified file(s) at the time the
21 'add' command is used. This means the 'commit' command will not consider
22 subsequent changes to already added content if it is not added again before
23 the commit.
25 The 'git status' command can be used to obtain a summary of what is included
26 for the next commit.
28 This command can be used to add ignored files with `-f` (force)
29 option, but they have to be
30 explicitly and exactly specified from the command line.  File globbing
31 and recursive behaviour do not add ignored files.
33 Please see gitlink:git-commit[1] for alternative ways to add content to a
34 commit.
37 OPTIONS
38 -------
39 <file>...::
40         Files to add content from.  Fileglobs (e.g. `*.c`) can
41         be given to add all matching files.  Also a
42         leading directory name (e.g. `dir` to add `dir/file1`
43         and `dir/file2`) can be given to add all files in the
44         directory, recursively.
46 -n::
47         Don't actually add the file(s), just show if they exist.
49 -v::
50         Be verbose.
52 -f::
53         Allow adding otherwise ignored files.
55 -i, \--interactive::
56         Add modified contents in the working tree interactively to
57         the index.
59 -u::
60         Update only files that git already knows about. This is similar
61         to what "git commit -a" does in preparation for making a commit,
62         except that the update is limited to paths specified on the
63         command line. If no paths are specified, all tracked files are
64         updated.
66 \--::
67         This option can be used to separate command-line options from
68         the list of files, (useful when filenames might be mistaken
69         for command-line options).
72 Configuration
73 -------------
75 The optional configuration variable 'core.excludesfile' indicates a path to a
76 file containing patterns of file names to exclude from git-add, similar to
77 $GIT_DIR/info/exclude.  Patterns in the exclude file are used in addition to
78 those in info/exclude.  See link:repository-layout.html[repository layout].
81 EXAMPLES
82 --------
83 git-add Documentation/\\*.txt::
85         Adds content from all `\*.txt` files under `Documentation`
86         directory and its subdirectories.
88 Note that the asterisk `\*` is quoted from the shell in this
89 example; this lets the command to include the files from
90 subdirectories of `Documentation/` directory.
92 git-add git-*.sh::
94         Considers adding content from all git-*.sh scripts.
95         Because this example lets shell expand the asterisk
96         (i.e. you are listing the files explicitly), it does not
97         consider `subdir/git-foo.sh`.
99 Interactive mode
100 ----------------
101 When the command enters the interactive mode, it shows the
102 output of the 'status' subcommand, and then goes into its
103 interactive command loop.
105 The command loop shows the list of subcommands available, and
106 gives a prompt "What now> ".  In general, when the prompt ends
107 with a single '>', you can pick only one of the choices given
108 and type return, like this:
110 ------------
111     *** Commands ***
112       1: status       2: update       3: revert       4: add untracked
113       5: patch        6: diff         7: quit         8: help
114     What now> 1
115 ------------
117 You also could say "s" or "sta" or "status" above as long as the
118 choice is unique.
120 The main command loop has 6 subcommands (plus help and quit).
122 status::
124    This shows the change between HEAD and index (i.e. what will be
125    committed if you say "git commit"), and between index and
126    working tree files (i.e. what you could stage further before
127    "git commit" using "git-add") for each path.  A sample output
128    looks like this:
130 ------------
131               staged     unstaged path
132      1:       binary      nothing foo.png
133      2:     +403/-35        +1/-1 git-add--interactive.perl
134 ------------
136 It shows that foo.png has differences from HEAD (but that is
137 binary so line count cannot be shown) and there is no
138 difference between indexed copy and the working tree
139 version (if the working tree version were also different,
140 'binary' would have been shown in place of 'nothing').  The
141 other file, git-add--interactive.perl, has 403 lines added
142 and 35 lines deleted if you commit what is in the index, but
143 working tree file has further modifications (one addition and
144 one deletion).
146 update::
148    This shows the status information and gives prompt
149    "Update>>".  When the prompt ends with double '>>', you can
150    make more than one selection, concatenated with whitespace or
151    comma.  Also you can say ranges.  E.g. "2-5 7,9" to choose
152    2,3,4,5,7,9 from the list.  You can say '*' to choose
153    everything.
155 What you chose are then highlighted with '*',
156 like this:
158 ------------
159            staged     unstaged path
160   1:       binary      nothing foo.png
161 * 2:     +403/-35        +1/-1 git-add--interactive.perl
162 ------------
164 To remove selection, prefix the input with `-`
165 like this:
167 ------------
168 Update>> -2
169 ------------
171 After making the selection, answer with an empty line to stage the
172 contents of working tree files for selected paths in the index.
174 revert::
176   This has a very similar UI to 'update', and the staged
177   information for selected paths are reverted to that of the
178   HEAD version.  Reverting new paths makes them untracked.
180 add untracked::
182   This has a very similar UI to 'update' and
183   'revert', and lets you add untracked paths to the index.
185 patch::
187   This lets you choose one path out of 'status' like selection.
188   After choosing the path, it presents diff between the index
189   and the working tree file and asks you if you want to stage
190   the change of each hunk.  You can say:
192        y - add the change from that hunk to index
193        n - do not add the change from that hunk to index
194        a - add the change from that hunk and all the rest to index
195        d - do not the change from that hunk nor any of the rest to index
196        j - do not decide on this hunk now, and view the next
197            undecided hunk
198        J - do not decide on this hunk now, and view the next hunk
199        k - do not decide on this hunk now, and view the previous
200            undecided hunk
201        K - do not decide on this hunk now, and view the previous hunk
203 After deciding the fate for all hunks, if there is any hunk
204 that was chosen, the index is updated with the selected hunks.
206 diff::
208   This lets you review what will be committed (i.e. between
209   HEAD and index).
212 See Also
213 --------
214 gitlink:git-status[1]
215 gitlink:git-rm[1]
216 gitlink:git-mv[1]
217 gitlink:git-commit[1]
218 gitlink:git-update-index[1]
220 Author
221 ------
222 Written by Linus Torvalds <torvalds@osdl.org>
224 Documentation
225 --------------
226 Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
230 Part of the gitlink:git[7] suite