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