git-commit.txt: clarify --patch mode with pathspec
[git] / Documentation / git-commit.txt
1 git-commit(1)
2 =============
3
4 NAME
5 ----
6 git-commit - Record changes to the repository
7
8 SYNOPSIS
9 --------
10 [verse]
11 'git commit' [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend]
12            [--dry-run] [(-c | -C | --fixup | --squash) <commit>]
13            [-F <file> | -m <msg>] [--reset-author] [--allow-empty]
14            [--allow-empty-message] [--no-verify] [-e] [--author=<author>]
15            [--date=<date>] [--cleanup=<mode>] [--[no-]status]
16            [-i | -o] [-S[<keyid>]] [--] [<file>...]
17
18 DESCRIPTION
19 -----------
20 Stores the current contents of the index in a new commit along
21 with a log message from the user describing the changes.
22
23 The content to be added can be specified in several ways:
24
25 1. by using 'git add' to incrementally "add" changes to the
26    index before using the 'commit' command (Note: even modified
27    files must be "added");
28
29 2. by using 'git rm' to remove files from the working tree
30    and the index, again before using the 'commit' command;
31
32 3. by listing files as arguments to the 'commit' command
33    (without --interactive or --patch switch), in which
34    case the commit will ignore changes staged in the index, and instead
35    record the current content of the listed files (which must already
36    be known to Git);
37
38 4. by using the -a switch with the 'commit' command to automatically
39    "add" changes from all known files (i.e. all files that are already
40    listed in the index) and to automatically "rm" files in the index
41    that have been removed from the working tree, and then perform the
42    actual commit;
43
44 5. by using the --interactive or --patch switches with the 'commit' command
45    to decide one by one which files or hunks should be part of the commit
46    in addition to contents in the index,
47    before finalizing the operation. See the ``Interactive Mode'' section of
48    linkgit:git-add[1] to learn how to operate these modes.
49
50 The `--dry-run` option can be used to obtain a
51 summary of what is included by any of the above for the next
52 commit by giving the same set of parameters (options and paths).
53
54 If you make a commit and then find a mistake immediately after
55 that, you can recover from it with 'git reset'.
56
57
58 OPTIONS
59 -------
60 -a::
61 --all::
62         Tell the command to automatically stage files that have
63         been modified and deleted, but new files you have not
64         told Git about are not affected.
65
66 -p::
67 --patch::
68         Use the interactive patch selection interface to chose
69         which changes to commit. See linkgit:git-add[1] for
70         details.
71
72 -C <commit>::
73 --reuse-message=<commit>::
74         Take an existing commit object, and reuse the log message
75         and the authorship information (including the timestamp)
76         when creating the commit.
77
78 -c <commit>::
79 --reedit-message=<commit>::
80         Like '-C', but with '-c' the editor is invoked, so that
81         the user can further edit the commit message.
82
83 --fixup=<commit>::
84         Construct a commit message for use with `rebase --autosquash`.
85         The commit message will be the subject line from the specified
86         commit with a prefix of "fixup! ".  See linkgit:git-rebase[1]
87         for details.
88
89 --squash=<commit>::
90         Construct a commit message for use with `rebase --autosquash`.
91         The commit message subject line is taken from the specified
92         commit with a prefix of "squash! ".  Can be used with additional
93         commit message options (`-m`/`-c`/`-C`/`-F`). See
94         linkgit:git-rebase[1] for details.
95
96 --reset-author::
97         When used with -C/-c/--amend options, or when committing after a
98         a conflicting cherry-pick, declare that the authorship of the
99         resulting commit now belongs to the committer. This also renews
100         the author timestamp.
101
102 --short::
103         When doing a dry-run, give the output in the short-format. See
104         linkgit:git-status[1] for details. Implies `--dry-run`.
105
106 --branch::
107         Show the branch and tracking info even in short-format.
108
109 --porcelain::
110         When doing a dry-run, give the output in a porcelain-ready
111         format. See linkgit:git-status[1] for details. Implies
112         `--dry-run`.
113
114 --long::
115         When doing a dry-run, give the output in a the long-format.
116         Implies `--dry-run`.
117
118 -z::
119 --null::
120         When showing `short` or `porcelain` status output, terminate
121         entries in the status output with NUL, instead of LF. If no
122         format is given, implies the `--porcelain` output format.
123
124 -F <file>::
125 --file=<file>::
126         Take the commit message from the given file.  Use '-' to
127         read the message from the standard input.
128
129 --author=<author>::
130         Override the commit author. Specify an explicit author using the
131         standard `A U Thor <author@example.com>` format. Otherwise <author>
132         is assumed to be a pattern and is used to search for an existing
133         commit by that author (i.e. rev-list --all -i --author=<author>);
134         the commit author is then copied from the first such commit found.
135
136 --date=<date>::
137         Override the author date used in the commit.
138
139 -m <msg>::
140 --message=<msg>::
141         Use the given <msg> as the commit message.
142         If multiple `-m` options are given, their values are
143         concatenated as separate paragraphs.
144
145 -t <file>::
146 --template=<file>::
147         When editing the commit message, start the editor with the
148         contents in the given file.  The `commit.template` configuration
149         variable is often used to give this option implicitly to the
150         command.  This mechanism can be used by projects that want to
151         guide participants with some hints on what to write in the message
152         in what order.  If the user exits the editor without editing the
153         message, the commit is aborted.  This has no effect when a message
154         is given by other means, e.g. with the `-m` or `-F` options.
155
156 -s::
157 --signoff::
158         Add Signed-off-by line by the committer at the end of the commit
159         log message.  The meaning of a signoff depends on the project,
160         but it typically certifies that committer has
161         the rights to submit this work under the same license and
162         agrees to a Developer Certificate of Origin
163         (see http://developercertificate.org/ for more information).
164
165 -n::
166 --no-verify::
167         This option bypasses the pre-commit and commit-msg hooks.
168         See also linkgit:githooks[5].
169
170 --allow-empty::
171         Usually recording a commit that has the exact same tree as its
172         sole parent commit is a mistake, and the command prevents you
173         from making such a commit.  This option bypasses the safety, and
174         is primarily for use by foreign SCM interface scripts.
175
176 --allow-empty-message::
177        Like --allow-empty this command is primarily for use by foreign
178        SCM interface scripts. It allows you to create a commit with an
179        empty commit message without using plumbing commands like
180        linkgit:git-commit-tree[1].
181
182 --cleanup=<mode>::
183         This option determines how the supplied commit message should be
184         cleaned up before committing.  The '<mode>' can be `strip`,
185         `whitespace`, `verbatim`, `scissors` or `default`.
186 +
187 --
188 strip::
189         Strip leading and trailing empty lines, trailing whitespace,
190         commentary and collapse consecutive empty lines.
191 whitespace::
192         Same as `strip` except #commentary is not removed.
193 verbatim::
194         Do not change the message at all.
195 scissors::
196         Same as `whitespace`, except that everything from (and
197         including) the line
198         "`# ------------------------ >8 ------------------------`"
199         is truncated if the message is to be edited. "`#`" can be
200         customized with core.commentChar.
201 default::
202         Same as `strip` if the message is to be edited.
203         Otherwise `whitespace`.
204 --
205 +
206 The default can be changed by the 'commit.cleanup' configuration
207 variable (see linkgit:git-config[1]).
208
209 -e::
210 --edit::
211         The message taken from file with `-F`, command line with
212         `-m`, and from commit object with `-C` are usually used as
213         the commit log message unmodified. This option lets you
214         further edit the message taken from these sources.
215
216 --no-edit::
217         Use the selected commit message without launching an editor.
218         For example, `git commit --amend --no-edit` amends a commit
219         without changing its commit message.
220
221 --amend::
222         Replace the tip of the current branch by creating a new
223         commit. The recorded tree is prepared as usual (including
224         the effect of the `-i` and `-o` options and explicit
225         pathspec), and the message from the original commit is used
226         as the starting point, instead of an empty message, when no
227         other message is specified from the command line via options
228         such as `-m`, `-F`, `-c`, etc.  The new commit has the same
229         parents and author as the current one (the `--reset-author`
230         option can countermand this).
231 +
232 --
233 It is a rough equivalent for:
234 ------
235         $ git reset --soft HEAD^
236         $ ... do something else to come up with the right tree ...
237         $ git commit -c ORIG_HEAD
238
239 ------
240 but can be used to amend a merge commit.
241 --
242 +
243 You should understand the implications of rewriting history if you
244 amend a commit that has already been published.  (See the "RECOVERING
245 FROM UPSTREAM REBASE" section in linkgit:git-rebase[1].)
246
247 --no-post-rewrite::
248         Bypass the post-rewrite hook.
249
250 -i::
251 --include::
252         Before making a commit out of staged contents so far,
253         stage the contents of paths given on the command line
254         as well.  This is usually not what you want unless you
255         are concluding a conflicted merge.
256
257 -o::
258 --only::
259         Make a commit by taking the updated working tree contents
260         of the paths specified on the
261         command line, disregarding any contents that have been
262         staged for other paths. This is the default mode of operation of
263         'git commit' if any paths are given on the command line,
264         in which case this option can be omitted.
265         If this option is specified together with '--amend', then
266         no paths need to be specified, which can be used to amend
267         the last commit without committing changes that have
268         already been staged.
269
270 -u[<mode>]::
271 --untracked-files[=<mode>]::
272         Show untracked files.
273 +
274 The mode parameter is optional (defaults to 'all'), and is used to
275 specify the handling of untracked files; when -u is not used, the
276 default is 'normal', i.e. show untracked files and directories.
277 +
278 The possible options are:
279 +
280         - 'no'     - Show no untracked files
281         - 'normal' - Shows untracked files and directories
282         - 'all'    - Also shows individual files in untracked directories.
283 +
284 The default can be changed using the status.showUntrackedFiles
285 configuration variable documented in linkgit:git-config[1].
286
287 -v::
288 --verbose::
289         Show unified diff between the HEAD commit and what
290         would be committed at the bottom of the commit message
291         template to help the user describe the commit by reminding
292         what changes the commit has.
293         Note that this diff output doesn't have its
294         lines prefixed with '#'. This diff will not be a part
295         of the commit message.
296 +
297 If specified twice, show in addition the unified diff between
298 what would be committed and the worktree files, i.e. the unstaged
299 changes to tracked files.
300
301 -q::
302 --quiet::
303         Suppress commit summary message.
304
305 --dry-run::
306         Do not create a commit, but show a list of paths that are
307         to be committed, paths with local changes that will be left
308         uncommitted and paths that are untracked.
309
310 --status::
311         Include the output of linkgit:git-status[1] in the commit
312         message template when using an editor to prepare the commit
313         message.  Defaults to on, but can be used to override
314         configuration variable commit.status.
315
316 --no-status::
317         Do not include the output of linkgit:git-status[1] in the
318         commit message template when using an editor to prepare the
319         default commit message.
320
321 -S[<keyid>]::
322 --gpg-sign[=<keyid>]::
323         GPG-sign commits. The `keyid` argument is optional and
324         defaults to the committer identity; if specified, it must be
325         stuck to the option without a space.
326
327 --no-gpg-sign::
328         Countermand `commit.gpgSign` configuration variable that is
329         set to force each and every commit to be signed.
330
331 \--::
332         Do not interpret any more arguments as options.
333
334 <file>...::
335         When files are given on the command line, the command
336         commits the contents of the named files, without
337         recording the changes already staged.  The contents of
338         these files are also staged for the next commit on top
339         of what have been staged before.
340
341 :git-commit: 1
342 include::date-formats.txt[]
343
344 EXAMPLES
345 --------
346 When recording your own work, the contents of modified files in
347 your working tree are temporarily stored to a staging area
348 called the "index" with 'git add'.  A file can be
349 reverted back, only in the index but not in the working tree,
350 to that of the last commit with `git reset HEAD -- <file>`,
351 which effectively reverts 'git add' and prevents the changes to
352 this file from participating in the next commit.  After building
353 the state to be committed incrementally with these commands,
354 `git commit` (without any pathname parameter) is used to record what
355 has been staged so far.  This is the most basic form of the
356 command.  An example:
357
358 ------------
359 $ edit hello.c
360 $ git rm goodbye.c
361 $ git add hello.c
362 $ git commit
363 ------------
364
365 Instead of staging files after each individual change, you can
366 tell `git commit` to notice the changes to the files whose
367 contents are tracked in
368 your working tree and do corresponding `git add` and `git rm`
369 for you.  That is, this example does the same as the earlier
370 example if there is no other change in your working tree:
371
372 ------------
373 $ edit hello.c
374 $ rm goodbye.c
375 $ git commit -a
376 ------------
377
378 The command `git commit -a` first looks at your working tree,
379 notices that you have modified hello.c and removed goodbye.c,
380 and performs necessary `git add` and `git rm` for you.
381
382 After staging changes to many files, you can alter the order the
383 changes are recorded in, by giving pathnames to `git commit`.
384 When pathnames are given, the command makes a commit that
385 only records the changes made to the named paths:
386
387 ------------
388 $ edit hello.c hello.h
389 $ git add hello.c hello.h
390 $ edit Makefile
391 $ git commit Makefile
392 ------------
393
394 This makes a commit that records the modification to `Makefile`.
395 The changes staged for `hello.c` and `hello.h` are not included
396 in the resulting commit.  However, their changes are not lost --
397 they are still staged and merely held back.  After the above
398 sequence, if you do:
399
400 ------------
401 $ git commit
402 ------------
403
404 this second commit would record the changes to `hello.c` and
405 `hello.h` as expected.
406
407 After a merge (initiated by 'git merge' or 'git pull') stops
408 because of conflicts, cleanly merged
409 paths are already staged to be committed for you, and paths that
410 conflicted are left in unmerged state.  You would have to first
411 check which paths are conflicting with 'git status'
412 and after fixing them manually in your working tree, you would
413 stage the result as usual with 'git add':
414
415 ------------
416 $ git status | grep unmerged
417 unmerged: hello.c
418 $ edit hello.c
419 $ git add hello.c
420 ------------
421
422 After resolving conflicts and staging the result, `git ls-files -u`
423 would stop mentioning the conflicted path.  When you are done,
424 run `git commit` to finally record the merge:
425
426 ------------
427 $ git commit
428 ------------
429
430 As with the case to record your own changes, you can use `-a`
431 option to save typing.  One difference is that during a merge
432 resolution, you cannot use `git commit` with pathnames to
433 alter the order the changes are committed, because the merge
434 should be recorded as a single commit.  In fact, the command
435 refuses to run when given pathnames (but see `-i` option).
436
437
438 DISCUSSION
439 ----------
440
441 Though not required, it's a good idea to begin the commit message
442 with a single short (less than 50 character) line summarizing the
443 change, followed by a blank line and then a more thorough description.
444 The text up to the first blank line in a commit message is treated
445 as the commit title, and that title is used throughout Git.
446 For example, linkgit:git-format-patch[1] turns a commit into email, and it uses
447 the title on the Subject line and the rest of the commit in the body.
448
449 include::i18n.txt[]
450
451 ENVIRONMENT AND CONFIGURATION VARIABLES
452 ---------------------------------------
453 The editor used to edit the commit log message will be chosen from the
454 GIT_EDITOR environment variable, the core.editor configuration variable, the
455 VISUAL environment variable, or the EDITOR environment variable (in that
456 order).  See linkgit:git-var[1] for details.
457
458 HOOKS
459 -----
460 This command can run `commit-msg`, `prepare-commit-msg`, `pre-commit`,
461 and `post-commit` hooks.  See linkgit:githooks[5] for more
462 information.
463
464 FILES
465 -----
466
467 `$GIT_DIR/COMMIT_EDITMSG`::
468         This file contains the commit message of a commit in progress.
469         If `git commit` exits due to an error before creating a commit,
470         any commit message that has been provided by the user (e.g., in
471         an editor session) will be available in this file, but will be
472         overwritten by the next invocation of `git commit`.
473
474 SEE ALSO
475 --------
476 linkgit:git-add[1],
477 linkgit:git-rm[1],
478 linkgit:git-mv[1],
479 linkgit:git-merge[1],
480 linkgit:git-commit-tree[1]
481
482 GIT
483 ---
484 Part of the linkgit:git[1] suite