Code

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