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