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