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