1GIT-ADD(1) Git Manual GIT-ADD(1)
2
3
4
6 git-add - Add file contents to the index
7
9 git add [-n] [-v] [--force | -f] [--interactive | -i] [--patch | -p]
10 [--edit | -e] [--all | [--update | -u]] [--intent-to-add | -N]
11 [--refresh] [--ignore-errors] [--] [<filepattern>...]
12
13
15 This command updates the index using the current content found in the
16 working tree, to prepare the content staged for the next commit. It
17 typically adds the current content of existing paths as a whole, but
18 with some options it can also be used to add content with only part of
19 the changes made to the working tree files applied, or remove paths
20 that do not exist in the working tree anymore.
21
22 The "index" holds a snapshot of the content of the working tree, and it
23 is this snapshot that is taken as the contents of the next commit. Thus
24 after making any changes to the working directory, and before running
25 the commit command, you must use the add command to add any new or
26 modified files to the index.
27
28 This command can be performed multiple times before a commit. It only
29 adds the content of the specified file(s) at the time the add command
30 is run; if you want subsequent changes included in the next commit,
31 then you must run git add again to add the new content to the index.
32
33 The git status command can be used to obtain a summary of which files
34 have changes that are staged for the next commit.
35
36 The git add command will not add ignored files by default. If any
37 ignored files were explicitly specified on the command line, git add
38 will fail with a list of ignored files. Ignored files reached by
39 directory recursion or filename globbing performed by Git (quote your
40 globs before the shell) will be silently ignored. The git add command
41 can be used to add ignored files with the -f (force) option.
42
43 Please see git-commit(1) for alternative ways to add content to a
44 commit.
45
47 <filepattern>...
48 Files to add content from. Fileglobs (e.g. *.c) can be given to
49 add all matching files. Also a leading directory name (e.g. dir to
50 add dir/file1 and dir/file2) can be given to add all files in the
51 directory, recursively.
52
53 -n, --dry-run
54 Don’t actually add the file(s), just show if they exist.
55
56 -v, --verbose
57 Be verbose.
58
59 -f, --force
60 Allow adding otherwise ignored files.
61
62 -i, --interactive
63 Add modified contents in the working tree interactively to the
64 index. Optional path arguments may be supplied to limit operation
65 to a subset of the working tree. See “Interactive mode” for
66 details.
67
68 -p, --patch
69 Interactively choose hunks of patch between the index and the work
70 tree and add them to the index. This gives the user a chance to
71 review the difference before adding modified contents to the index.
72
73 This effectively runs add --interactive, but bypasses the initial
74 command menu and directly jumps to the patch subcommand. See
75 “Interactive mode” for details.
76
77 -e, --edit
78 Open the diff vs. the index in an editor and let the user edit it.
79 After the editor was closed, adjust the hunk headers and apply the
80 patch to the index.
81
82 NOTE: Obviously, if you change anything else than the first
83 character on lines beginning with a space or a minus, the patch
84 will no longer apply.
85
86 -u, --update
87 Only match <filepattern> against already tracked files in the index
88 rather than the working tree. That means that it will never stage
89 new files, but that it will stage modified new contents of tracked
90 files and that it will remove files from the index if the
91 corresponding files in the working tree have been removed.
92
93 If no <filepattern> is given, default to "."; in other words,
94 update all tracked files in the current directory and its
95 subdirectories.
96
97 -A, --all
98 Like -u, but match <filepattern> against files in the working tree
99 in addition to the index. That means that it will find new files as
100 well as staging modified content and removing files that are no
101 longer in the working tree.
102
103 -N, --intent-to-add
104 Record only the fact that the path will be added later. An entry
105 for the path is placed in the index with no content. This is useful
106 for, among other things, showing the unstaged content of such files
107 with git diff and committing them with git commit -a.
108
109 --refresh
110 Don’t add the file(s), but only refresh their stat() information in
111 the index.
112
113 --ignore-errors
114 If some files could not be added because of errors indexing them,
115 do not abort the operation, but continue adding the others. The
116 command shall still exit with non-zero status.
117
118 --
119 This option can be used to separate command-line options from the
120 list of files, (useful when filenames might be mistaken for
121 command-line options).
122
124 The optional configuration variable core.excludesfile indicates a path
125 to a file containing patterns of file names to exclude from git-add,
126 similar to $GIT_DIR/info/exclude. Patterns in the exclude file are used
127 in addition to those in info/exclude. See gitrepository-layout(5).
128
130 · Adds content from all \*.txt files under Documentation directory
131 and its subdirectories:
132
133 $ git add Documentation/\*.txt
134
135 Note that the asterisk \* is quoted from the shell in this example;
136 this lets the command include the files from subdirectories of
137 Documentation/ directory.
138
139 · Considers adding content from all git-*.sh scripts:
140
141 $ git add git-*.sh
142
143 Because this example lets the shell expand the asterisk (i.e. you
144 are listing the files explicitly), it does not consider
145 subdir/git-foo.sh.
146
148 When the command enters the interactive mode, it shows the output of
149 the status subcommand, and then goes into its interactive command loop.
150
151 The command loop shows the list of subcommands available, and gives a
152 prompt "What now> ". In general, when the prompt ends with a single >,
153 you can pick only one of the choices given and type return, like this:
154
155 *** Commands ***
156 1: status 2: update 3: revert 4: add untracked
157 5: patch 6: diff 7: quit 8: help
158 What now> 1
159
160
161 You also could say s or sta or status above as long as the choice is
162 unique.
163
164 The main command loop has 6 subcommands (plus help and quit).
165
166 status
167 This shows the change between HEAD and index (i.e. what will be
168 committed if you say git commit), and between index and working
169 tree files (i.e. what you could stage further before git commit
170 using git add) for each path. A sample output looks like this:
171
172 staged unstaged path
173 1: binary nothing foo.png
174 2: +403/-35 +1/-1 git-add--interactive.perl
175
176 It shows that foo.png has differences from HEAD (but that is binary
177 so line count cannot be shown) and there is no difference between
178 indexed copy and the working tree version (if the working tree
179 version were also different, binary would have been shown in place
180 of nothing). The other file, git-add—interactive.perl, has 403
181 lines added and 35 lines deleted if you commit what is in the
182 index, but working tree file has further modifications (one
183 addition and one deletion).
184
185 update
186 This shows the status information and issues an "Update>>" prompt.
187 When the prompt ends with double >>, you can make more than one
188 selection, concatenated with whitespace or comma. Also you can say
189 ranges. E.g. "2-5 7,9" to choose 2,3,4,5,7,9 from the list. If the
190 second number in a range is omitted, all remaining patches are
191 taken. E.g. "7-" to choose 7,8,9 from the list. You can say * to
192 choose everything.
193
194 What you chose are then highlighted with *, like this:
195
196 staged unstaged path
197 1: binary nothing foo.png
198 * 2: +403/-35 +1/-1 git-add--interactive.perl
199
200 To remove selection, prefix the input with - like this:
201
202 Update>> -2
203
204 After making the selection, answer with an empty line to stage the
205 contents of working tree files for selected paths in the index.
206
207 revert
208 This has a very similar UI to update, and the staged information
209 for selected paths are reverted to that of the HEAD version.
210 Reverting new paths makes them untracked.
211
212 add untracked
213 This has a very similar UI to update and revert, and lets you add
214 untracked paths to the index.
215
216 patch
217 This lets you choose one path out of a status like selection. After
218 choosing the path, it presents the diff between the index and the
219 working tree file and asks you if you want to stage the change of
220 each hunk. You can say:
221
222 y - stage this hunk
223 n - do not stage this hunk
224 q - quit, do not stage this hunk nor any of the remaining ones
225 a - stage this and all the remaining hunks in the file
226 d - do not stage this hunk nor any of the remaining hunks in the file
227 g - select a hunk to go to
228 / - search for a hunk matching the given regex
229 j - leave this hunk undecided, see next undecided hunk
230 J - leave this hunk undecided, see next hunk
231 k - leave this hunk undecided, see previous undecided hunk
232 K - leave this hunk undecided, see previous hunk
233 s - split the current hunk into smaller hunks
234 e - manually edit the current hunk
235 ? - print help
236
237 After deciding the fate for all hunks, if there is any hunk that
238 was chosen, the index is updated with the selected hunks.
239
240 diff
241 This lets you review what will be committed (i.e. between HEAD and
242 index).
243
245 git-status(1) git-rm(1) git-reset(1) git-mv(1) git-commit(1) git-
246 update-index(1)
247
249 Written by Linus Torvalds <torvalds@osdl.org[1]>
250
252 Documentation by Junio C Hamano and the git-list
253 <git@vger.kernel.org[2]>.
254
256 Part of the git(1) suite
257
259 1. torvalds@osdl.org
260 mailto:torvalds@osdl.org
261
262 2. git@vger.kernel.org
263 mailto:git@vger.kernel.org
264
265
266
267Git 1.7.1 08/16/2017 GIT-ADD(1)