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] [-f] [--interactive | -i] [-u] [--refresh]
10 [--] <filepattern>...
11
13 This command adds the current content of new or modified files to the
14 index, thus staging that content for inclusion in the next commit.
15
16 The "index" holds a snapshot of the content of the working tree, and it
17 is this snapshot that is taken as the contents of the next commit. Thus
18 after making any changes to the working directory, and before running
19 the commit command, you must use the add command to add any new or
20 modified files to the index.
21
22 This command can be performed multiple times before a commit. It only
23 adds the content of the specified file(s) at the time the add command
24 is run; if you want subsequent changes included in the next commit,
25 then you must run git add again to add the new content to the index.
26
27 The git status command can be used to obtain a summary of which files
28 have changes that are staged for the next commit.
29
30 The git add command will not add ignored files by default. If any
31 ignored files were explicitly specified on the command line, git add
32 will fail with a list of ignored files. Ignored files reached by
33 directory recursion or filename globbing performed by Git (quote your
34 globs before the shell) will be silently ignored. The add command can
35 be used to add ignored files with the -f (force) option.
36
37 Please see git-commit(1) for alternative ways to add content to a
38 commit.
39
41 <filepattern>...
42 Files to add content from. Fileglobs (e.g. *.c) can be given to add
43 all matching files. Also a leading directory name (e.g. dir to add
44 dir/file1 and dir/file2) can be given to add all files in the
45 directory, recursively.
46
47 -n
48 Don´t actually add the file(s), just show if they exist.
49
50 -v
51 Be verbose.
52
53 -f
54 Allow adding otherwise ignored files.
55
56 -i, --interactive
57 Add modified contents in the working tree interactively to the
58 index.
59
60 -u
61 Update only files that git already knows about. This is similar to
62 what "git commit -a" does in preparation for making a commit,
63 except that the update is limited to paths specified on the command
64 line. If no paths are specified, all tracked files are updated.
65
66 --refresh
67 Don´t add the file(s), but only refresh their stat() information in
68 the index.
69
70 --
71 This option can be used to separate command-line options from the
72 list of files, (useful when filenames might be mistaken for
73 command-line options).
74
76 The optional configuration variable core.excludesfile indicates a path
77 to a file containing patterns of file names to exclude from git-add,
78 similar to $GIT_DIR/info/exclude. Patterns in the exclude file are used
79 in addition to those in info/exclude. See repository layout[1].
80
82 git-add Documentation/\*.txt
83 Adds content from all *.txt files under Documentation directory and
84 its subdirectories.
85
86 Note that the asterisk * is quoted from the shell in this example;
87 this lets the command to include the files from subdirectories of
88 Documentation/ directory.
89
90 git-add git-*.sh
91 Considers adding content from all git-*.sh scripts. Because this
92 example lets shell expand the asterisk (i.e. you are listing the
93 files explicitly), it does not consider subdir/git-foo.sh.
94
96 When the command enters the interactive mode, it shows the output of
97 the status subcommand, and then goes into its interactive command loop.
98
99 The command loop shows the list of subcommands available, and gives a
100 prompt "What now> ". In general, when the prompt ends with a single >,
101 you can pick only one of the choices given and type return, like this:
102
103
104
105 *** Commands ***
106 1: status 2: update 3: revert 4: add untracked
107 5: patch 6: diff 7: quit 8: help
108 What now> 1
109
110 You also could say "s" or "sta" or "status" above as long as the choice
111 is unique.
112
113 The main command loop has 6 subcommands (plus help and quit).
114
115 status
116 This shows the change between HEAD and index (i.e. what will be
117 committed if you say "git commit"), and between index and working
118 tree files (i.e. what you could stage further before "git commit"
119 using "git-add") for each path. A sample output looks like this:
120
121
122
123 staged unstaged path
124 1: binary nothing foo.png
125 2: +403/-35 +1/-1 git-add--interactive.perl
126
127 It shows that foo.png has differences from HEAD (but that is binary
128 so line count cannot be shown) and there is no difference between
129 indexed copy and the working tree version (if the working tree
130 version were also different, binary would have been shown in place
131 of nothing). The other file, git-add--interactive.perl, has 403
132 lines added and 35 lines deleted if you commit what is in the
133 index, but working tree file has further modifications (one
134 addition and one deletion).
135
136 update
137 This shows the status information and gives prompt "Update>>". When
138 the prompt ends with double >>, you can make more than one
139 selection, concatenated with whitespace or comma. Also you can say
140 ranges. E.g. "2-5 7,9" to choose 2,3,4,5,7,9 from the list. You can
141 say * to choose everything.
142
143 What you chose are then highlighted with *, like this:
144
145
146
147 staged unstaged path
148 1: binary nothing foo.png
149 * 2: +403/-35 +1/-1 git-add--interactive.perl
150
151 To remove selection, prefix the input with - like this:
152
153
154
155 Update>> -2
156
157 After making the selection, answer with an empty line to stage the
158 contents of working tree files for selected paths in the index.
159
160 revert
161 This has a very similar UI to update, and the staged information
162 for selected paths are reverted to that of the HEAD version.
163 Reverting new paths makes them untracked.
164
165 add untracked
166 This has a very similar UI to update and revert, and lets you add
167 untracked paths to the index.
168
169 patch
170 This lets you choose one path out of status like selection. After
171 choosing the path, it presents diff between the index and the
172 working tree file and asks you if you want to stage the change of
173 each hunk. You can say:
174
175
176 y - add the change from that hunk to index
177 n - do not add the change from that hunk to index
178 a - add the change from that hunk and all the rest to index
179 d - do not the change from that hunk nor any of the rest to index
180 j - do not decide on this hunk now, and view the next
181 undecided hunk
182 J - do not decide on this hunk now, and view the next hunk
183 k - do not decide on this hunk now, and view the previous
184 undecided hunk
185 K - do not decide on this hunk now, and view the previous hunk
186 After deciding the fate for all hunks, if there is any hunk that
187 was chosen, the index is updated with the selected hunks.
188
189 diff
190 This lets you review what will be committed (i.e. between HEAD and
191 index).
192
194 git-status(1) git-rm(1) git-mv(1) git-commit(1) git-update-index(1)
195
197 Written by Linus Torvalds <torvalds@osdl.org>
198
200 Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
201
203 Part of the git(7) suite
204
206 1. repository layout
207 repository-layout.html
208
209
210
211Git 1.5.3.3 10/09/2007 GIT-ADD(1)