Merge branch 'master' of git://repo.or.cz/git-gui
[git] / Documentation / git-add.txt
1 git-add(1)
2 ==========
3
4 NAME
5 ----
6 git-add - Add file contents to the changeset to be committed next
7
8 SYNOPSIS
9 --------
10 'git-add' [-n] [-v] [-f] [--interactive | -i] [-u] [--] <file>...
11
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.
18
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.
24
25 The 'git status' command can be used to obtain a summary of what is included
26 for the next commit.
27
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.
32
33 Please see gitlink:git-commit[1] for alternative ways to add content to a
34 commit.
35
36
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.
45
46 -n::
47         Don't actually add the file(s), just show if they exist.
48
49 -v::
50         Be verbose.
51
52 -f::
53         Allow adding otherwise ignored files.
54
55 -i, \--interactive::
56         Add modified contents in the working tree interactively to
57         the index.
58
59 -u::
60         Update all files that git already knows about. This is what
61         "git commit -a" does in preparation for making a commit.
62
63 \--::
64         This option can be used to separate command-line options from
65         the list of files, (useful when filenames might be mistaken
66         for command-line options).
67
68
69 EXAMPLES
70 --------
71 git-add Documentation/\\*.txt::
72
73         Adds content from all `\*.txt` files under `Documentation`
74         directory and its subdirectories.
75 +
76 Note that the asterisk `\*` is quoted from the shell in this
77 example; this lets the command to include the files from
78 subdirectories of `Documentation/` directory.
79
80 git-add git-*.sh::
81
82         Considers adding content from all git-*.sh scripts.
83         Because this example lets shell expand the asterisk
84         (i.e. you are listing the files explicitly), it does not
85         consider `subdir/git-foo.sh`.
86
87 Interactive mode
88 ----------------
89 When the command enters the interactive mode, it shows the
90 output of the 'status' subcommand, and then goes into its
91 interactive command loop.
92
93 The command loop shows the list of subcommands available, and
94 gives a prompt "What now> ".  In general, when the prompt ends
95 with a single '>', you can pick only one of the choices given
96 and type return, like this:
97
98 ------------
99     *** Commands ***
100       1: status       2: update       3: revert       4: add untracked
101       5: patch        6: diff         7: quit         8: help
102     What now> 1
103 ------------
104
105 You also could say "s" or "sta" or "status" above as long as the
106 choice is unique.
107
108 The main command loop has 6 subcommands (plus help and quit).
109
110 status::
111
112    This shows the change between HEAD and index (i.e. what will be
113    committed if you say "git commit"), and between index and
114    working tree files (i.e. what you could stage further before
115    "git commit" using "git-add") for each path.  A sample output
116    looks like this:
117 +
118 ------------
119               staged     unstaged path
120      1:       binary      nothing foo.png
121      2:     +403/-35        +1/-1 git-add--interactive.perl
122 ------------
123 +
124 It shows that foo.png has differences from HEAD (but that is
125 binary so line count cannot be shown) and there is no
126 difference between indexed copy and the working tree
127 version (if the working tree version were also different,
128 'binary' would have been shown in place of 'nothing').  The
129 other file, git-add--interactive.perl, has 403 lines added
130 and 35 lines deleted if you commit what is in the index, but
131 working tree file has further modifications (one addition and
132 one deletion).
133
134 update::
135
136    This shows the status information and gives prompt
137    "Update>>".  When the prompt ends with double '>>', you can
138    make more than one selection, concatenated with whitespace or
139    comma.  Also you can say ranges.  E.g. "2-5 7,9" to choose
140    2,3,4,5,7,9 from the list.  You can say '*' to choose
141    everything.
142 +
143 What you chose are then highlighted with '*',
144 like this:
145 +
146 ------------
147            staged     unstaged path
148   1:       binary      nothing foo.png
149 * 2:     +403/-35        +1/-1 git-add--interactive.perl
150 ------------
151 +
152 To remove selection, prefix the input with `-`
153 like this:
154 +
155 ------------
156 Update>> -2
157 ------------
158 +
159 After making the selection, answer with an empty line to stage the
160 contents of working tree files for selected paths in the index.
161
162 revert::
163
164   This has a very similar UI to 'update', and the staged
165   information for selected paths are reverted to that of the
166   HEAD version.  Reverting new paths makes them untracked.
167
168 add untracked::
169
170   This has a very similar UI to 'update' and
171   'revert', and lets you add untracked paths to the index.
172
173 patch::
174
175   This lets you choose one path out of 'status' like selection.
176   After choosing the path, it presents diff between the index
177   and the working tree file and asks you if you want to stage
178   the change of each hunk.  You can say:
179
180        y - add the change from that hunk to index
181        n - do not add the change from that hunk to index
182        a - add the change from that hunk and all the rest to index
183        d - do not the change from that hunk nor any of the rest to index
184        j - do not decide on this hunk now, and view the next
185            undecided hunk
186        J - do not decide on this hunk now, and view the next hunk
187        k - do not decide on this hunk now, and view the previous
188            undecided hunk
189        K - do not decide on this hunk now, and view the previous hunk
190 +
191 After deciding the fate for all hunks, if there is any hunk
192 that was chosen, the index is updated with the selected hunks.
193
194 diff::
195
196   This lets you review what will be committed (i.e. between
197   HEAD and index).
198
199
200 See Also
201 --------
202 gitlink:git-status[1]
203 gitlink:git-rm[1]
204 gitlink:git-mv[1]
205 gitlink:git-commit[1]
206 gitlink:git-update-index[1]
207
208 Author
209 ------
210 Written by Linus Torvalds <torvalds@osdl.org>
211
212 Documentation
213 --------------
214 Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
215
216 GIT
217 ---
218 Part of the gitlink:git[7] suite
219