blob: 4622297ec98cddc2e1f2e4417b9eeec11a3c91b1 [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231git-commit(1)
2=============
3
4NAME
5----
Junio C Hamano7c73c662007-01-19 00:37:506git-commit - Record changes to the repository
Junio C Hamano1a4e8412005-12-27 08:17:237
8SYNOPSIS
9--------
Junio C Hamano235a91e2006-01-07 01:13:5810[verse]
Junio C Hamano3d050d62011-05-17 06:43:3411'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>] [--status | --no-status]
16 [-i | -o] [--] [<file>...]
Junio C Hamano1a4e8412005-12-27 08:17:2317
18DESCRIPTION
19-----------
Junio C Hamanoba4b9282008-07-06 05:20:3120Stores the current contents of the index in a new commit along
21with a log message from the user describing the changes.
Junio C Hamano1a4e8412005-12-27 08:17:2322
Junio C Hamanobd2b4bb2007-08-06 06:42:2423The content to be added can be specified in several ways:
Junio C Hamanob515b6a2007-08-08 09:21:1624
Junio C Hamano1aa40d22010-01-21 17:46:43251. by using 'git add' to incrementally "add" changes to the
Junio C Hamanobd2b4bb2007-08-06 06:42:2426 index before using the 'commit' command (Note: even modified
Junio C Hamanoe7935c42006-12-13 21:32:1727 files must be "added");
Junio C Hamano2b135272006-03-18 07:45:4228
Junio C Hamano1aa40d22010-01-21 17:46:43292. by using 'git rm' to remove files from the working tree
Junio C Hamanobd2b4bb2007-08-06 06:42:2430 and the index, again before using the 'commit' command;
Junio C Hamano2b135272006-03-18 07:45:4231
Junio C Hamanobd2b4bb2007-08-06 06:42:24323. by listing files as arguments to the 'commit' command, in which
33 case the commit will ignore changes staged in the index, and instead
Junio C Hamano50819852008-11-19 02:07:5634 record the current content of the listed files (which must already
35 be known to git);
Junio C Hamanoe7935c42006-12-13 21:32:1736
Junio C Hamanobd2b4bb2007-08-06 06:42:24374. by using the -a switch with the 'commit' command to automatically
38 "add" changes from all known files (i.e. all files that are already
39 listed in the index) and to automatically "rm" files in the index
40 that have been removed from the working tree, and then perform the
41 actual commit;
Junio C Hamanoe7935c42006-12-13 21:32:1742
Junio C Hamano3d050d62011-05-17 06:43:34435. by using the --interactive or --patch switches with the 'commit' command
44 to decide one by one which files or hunks should be part of the commit,
Junio C Hamanob76a6862012-05-02 22:02:4645 before finalizing the operation. See the ``Interactive Mode'' section of
Junio C Hamano3d050d62011-05-17 06:43:3446 linkgit:git-add[1] to learn how to operate these modes.
Junio C Hamanoc51fede2007-03-12 07:29:2047
Junio C Hamano1bb31992009-08-29 04:24:0848The `--dry-run` option can be used to obtain a
Junio C Hamanoe7935c42006-12-13 21:32:1749summary of what is included by any of the above for the next
Junio C Hamano1bb31992009-08-29 04:24:0850commit by giving the same set of parameters (options and paths).
Junio C Hamanoe7935c42006-12-13 21:32:1751
Junio C Hamanofce7c7e2008-07-02 03:06:3852If you make a commit and then find a mistake immediately after
Junio C Hamano1aa40d22010-01-21 17:46:4353that, you can recover from it with 'git reset'.
Junio C Hamanoe7935c42006-12-13 21:32:1754
Junio C Hamano1a4e8412005-12-27 08:17:2355
56OPTIONS
57-------
Junio C Hamanoeb415992008-06-08 22:49:4758-a::
59--all::
Junio C Hamanoe7935c42006-12-13 21:32:1760Tell the command to automatically stage files that have
61been modified and deleted, but new files you have not
62told git about are not affected.
Junio C Hamano1a4e8412005-12-27 08:17:2363
Junio C Hamano3d050d62011-05-17 06:43:3464-p::
65--patch::
66Use the interactive patch selection interface to chose
67which changes to commit. See linkgit:git-add[1] for
68details.
69
Junio C Hamanoeb415992008-06-08 22:49:4770-C <commit>::
71--reuse-message=<commit>::
72Take an existing commit object, and reuse the log message
Junio C Hamano1a4e8412005-12-27 08:17:2373and the authorship information (including the timestamp)
Junio C Hamanoeb415992008-06-08 22:49:4774when creating the commit.
75
76-c <commit>::
77--reedit-message=<commit>::
78Like '-C', but with '-c' the editor is invoked, so that
79the user can further edit the commit message.
Junio C Hamano1a4e8412005-12-27 08:17:2380
Junio C Hamano2e6ded82010-12-05 06:20:4881--fixup=<commit>::
82Construct a commit message for use with `rebase --autosquash`.
83The commit message will be the subject line from the specified
84commit with a prefix of "fixup! ". See linkgit:git-rebase[1]
85for details.
86
87--squash=<commit>::
88Construct a commit message for use with `rebase --autosquash`.
89The commit message subject line is taken from the specified
90commit with a prefix of "squash! ". Can be used with additional
91commit message options (`-m`/`-c`/`-C`/`-F`). See
92linkgit:git-rebase[1] for details.
93
Junio C Hamano2bd8a742009-12-01 21:16:5994--reset-author::
Junio C Hamanoa8cc1d82011-03-10 01:18:1295When used with -C/-c/--amend options, or when committing after a
96a conflicting cherry-pick, declare that the authorship of the
97resulting commit now belongs of the committer. This also renews
98the author timestamp.
Junio C Hamano2bd8a742009-12-01 21:16:5999
Junio C Hamanoa0fae262009-12-28 09:33:50100--short::
101When doing a dry-run, give the output in the short-format. See
102linkgit:git-status[1] for details. Implies `--dry-run`.
103
Junio C Hamano9257a332012-06-25 20:01:02104--branch::
105Show the branch and tracking info even in short-format.
106
Junio C Hamanoa0fae262009-12-28 09:33:50107--porcelain::
108When doing a dry-run, give the output in a porcelain-ready
109format. See linkgit:git-status[1] for details. Implies
110`--dry-run`.
111
112-z::
Junio C Hamano9257a332012-06-25 20:01:02113--null::
Junio C Hamanoa0fae262009-12-28 09:33:50114When showing `short` or `porcelain` status output, terminate
115entries in the status output with NUL, instead of LF. If no
116format is given, implies the `--porcelain` output format.
117
Junio C Hamano1a4e8412005-12-27 08:17:23118-F <file>::
Junio C Hamanoeb415992008-06-08 22:49:47119--file=<file>::
Junio C Hamano1a4e8412005-12-27 08:17:23120Take the commit message from the given file. Use '-' to
121read the message from the standard input.
122
Junio C Hamanoeb415992008-06-08 22:49:47123--author=<author>::
Junio C Hamano13002fb2010-06-08 05:53:58124Override the commit author. Specify an explicit author using the
125standard `A U Thor <author@example.com>` format. Otherwise <author>
126is assumed to be a pattern and is used to search for an existing
127commit by that author (i.e. rev-list --all -i --author=<author>);
128the commit author is then copied from the first such commit found.
Junio C Hamano40f2f8d2006-02-07 08:04:39129
Junio C Hamanoae05fee2010-01-08 07:39:46130--date=<date>::
131Override the author date used in the commit.
132
Junio C Hamanoeb415992008-06-08 22:49:47133-m <msg>::
134--message=<msg>::
Junio C Hamano1a4e8412005-12-27 08:17:23135Use the given <msg> as the commit message.
136
Junio C Hamanoeb415992008-06-08 22:49:47137-t <file>::
138--template=<file>::
Junio C Hamano51f87de2012-04-16 21:18:54139When editing the commit message, start the editor with the
140contents in the given file. The `commit.template` configuration
141variable is often used to give this option implicitly to the
142command. This mechanism can be used by projects that want to
143guide participants with some hints on what to write in the message
144in what order. If the user exits the editor without editing the
145message, the commit is aborted. This has no effect when a message
146is given by other means, e.g. with the `-m` or `-F` options.
Junio C Hamanoa3770f92007-07-25 08:53:33147
Junio C Hamanoeb415992008-06-08 22:49:47148-s::
149--signoff::
Junio C Hamano610d1762008-11-28 06:27:13150Add Signed-off-by line by the committer at the end of the commit
Junio C Hamano7d06a8a2008-10-20 05:42:33151log message.
Junio C Hamano1a4e8412005-12-27 08:17:23152
Junio C Hamanoeb415992008-06-08 22:49:47153-n::
Junio C Hamanoe7935c42006-12-13 21:32:17154--no-verify::
Junio C Hamano942b35e2007-12-09 10:19:33155This option bypasses the pre-commit and commit-msg hooks.
Junio C Hamanofce7c7e2008-07-02 03:06:38156See also linkgit:githooks[5].
Junio C Hamano1a4e8412005-12-27 08:17:23157
Junio C Hamano0c999702007-12-03 09:57:55158--allow-empty::
159Usually recording a commit that has the exact same tree as its
Junio C Hamano58256872007-12-04 08:31:13160sole parent commit is a mistake, and the command prevents you
161from making such a commit. This option bypasses the safety, and
Junio C Hamano619596a2010-08-18 22:15:35162is primarily for use by foreign SCM interface scripts.
Junio C Hamano0c999702007-12-03 09:57:55163
Junio C Hamanocb39aea2010-05-09 07:24:48164--allow-empty-message::
165 Like --allow-empty this command is primarily for use by foreign
Junio C Hamano619596a2010-08-18 22:15:35166 SCM interface scripts. It allows you to create a commit with an
Junio C Hamanocb39aea2010-05-09 07:24:48167 empty commit message without using plumbing commands like
168 linkgit:git-commit-tree[1].
169
Junio C Hamano554da792007-12-27 03:29:58170--cleanup=<mode>::
171This option sets how the commit message is cleaned up.
172The '<mode>' can be one of 'verbatim', 'whitespace', 'strip',
173and 'default'. The 'default' mode will strip leading and
174trailing empty lines and #commentary from the commit message
175only if the message is to be edited. Otherwise only whitespace
176removed. The 'verbatim' mode does not change message at all,
177'whitespace' removes just leading/trailing whitespace lines
178and 'strip' removes both whitespace and commentary.
179
Junio C Hamanoeb415992008-06-08 22:49:47180-e::
181--edit::
Junio C Hamano1a4e8412005-12-27 08:17:23182The message taken from file with `-F`, command line with
183`-m`, and from file with `-C` are usually used as the
184commit log message unmodified. This option lets you
185further edit the message taken from these sources.
186
Junio C Hamanobfe9e752006-04-05 21:43:28187--amend::
Junio C Hamanobfe9e752006-04-05 21:43:28188Used to amend the tip of the current branch. Prepare the tree
189object you would want to replace the latest commit as usual
190(this includes the usual -i/-o and explicit paths), and the
191commit log editor is seeded with the commit message from the
192tip of the current branch. The commit you create replaces the
193current tip -- if it was a merge, it will have the parents of
194the current tip as parents -- so the current top commit is
195discarded.
Junio C Hamano9257a332012-06-25 20:01:02196
197--no-post-rewrite::
198Bypass the post-rewrite hook.
199
Junio C Hamanobfe9e752006-04-05 21:43:28200+
Junio C Hamano47ea30e2006-04-05 23:08:03201--
Junio C Hamanobfe9e752006-04-05 21:43:28202It is a rough equivalent for:
Junio C Hamano47ea30e2006-04-05 23:08:03203------
Junio C Hamanobfe9e752006-04-05 21:43:28204$ git reset --soft HEAD^
205$ ... do something else to come up with the right tree ...
206$ git commit -c ORIG_HEAD
Junio C Hamano47ea30e2006-04-05 23:08:03207
208------
Junio C Hamanobfe9e752006-04-05 21:43:28209but can be used to amend a merge commit.
Junio C Hamano47ea30e2006-04-05 23:08:03210--
Junio C Hamano7d06a8a2008-10-20 05:42:33211+
212You should understand the implications of rewriting history if you
213amend a commit that has already been published. (See the "RECOVERING
214FROM UPSTREAM REBASE" section in linkgit:git-rebase[1].)
Junio C Hamanobfe9e752006-04-05 21:43:28215
Junio C Hamanoeb415992008-06-08 22:49:47216-i::
217--include::
Junio C Hamanoe7935c42006-12-13 21:32:17218Before making a commit out of staged contents so far,
219stage the contents of paths given on the command line
220as well. This is usually not what you want unless you
221are concluding a conflicted merge.
Junio C Hamano1a4e8412005-12-27 08:17:23222
Junio C Hamanoeb415992008-06-08 22:49:47223-o::
224--only::
Junio C Hamanoe79159d2008-04-12 08:23:17225Make a commit only from the paths specified on the
226command line, disregarding any contents that have been
227staged so far. This is the default mode of operation of
Junio C Hamano1aa40d22010-01-21 17:46:43228'git commit' if any paths are given on the command line,
Junio C Hamanoe79159d2008-04-12 08:23:17229in which case this option can be omitted.
230If this option is specified together with '--amend', then
Junio C Hamano54bf1e22008-12-20 06:30:11231no paths need to be specified, which can be used to amend
Junio C Hamanoe79159d2008-04-12 08:23:17232the last commit without committing changes that have
233already been staged.
234
Junio C Hamano4224f992008-06-23 07:14:08235-u[<mode>]::
236--untracked-files[=<mode>]::
Junio C Hamano36a4dbc2011-02-22 07:51:32237Show untracked files.
Junio C Hamano4224f992008-06-23 07:14:08238+
Junio C Hamano36a4dbc2011-02-22 07:51:32239The mode parameter is optional (defaults to 'all'), and is used to
240specify the handling of untracked files; when -u is not used, the
241default is 'normal', i.e. show untracked files and directories.
Junio C Hamano4224f992008-06-23 07:14:08242+
Junio C Hamanoe1cca182010-02-20 20:01:23243The possible options are:
244+
Junio C Hamano4224f992008-06-23 07:14:08245- 'no' - Show no untracked files
246- 'normal' - Shows untracked files and directories
247- 'all' - Also shows individual files in untracked directories.
Junio C Hamano4224f992008-06-23 07:14:08248+
Junio C Hamano36a4dbc2011-02-22 07:51:32249The default can be changed using the status.showUntrackedFiles
250configuration variable documented in linkgit:git-config[1].
Junio C Hamano1e6e0062007-07-13 05:33:25251
Junio C Hamanoeb415992008-06-08 22:49:47252-v::
253--verbose::
Junio C Hamano1e6e0062007-07-13 05:33:25254Show unified diff between the HEAD commit and what
255would be committed at the bottom of the commit message
256template. Note that this diff output doesn't have its
257lines prefixed with '#'.
258
Junio C Hamanoeb415992008-06-08 22:49:47259-q::
260--quiet::
Junio C Hamanof9771f62007-01-17 17:42:30261Suppress commit summary message.
Junio C Hamano7d23f5e2006-12-16 07:44:04262
Junio C Hamano1bb31992009-08-29 04:24:08263--dry-run::
264Do not create a commit, but show a list of paths that are
265to be committed, paths with local changes that will be left
266uncommitted and paths that are untracked.
267
Junio C Hamano6ce6b6c2010-01-18 01:25:50268--status::
269Include the output of linkgit:git-status[1] in the commit
270message template when using an editor to prepare the commit
271message. Defaults to on, but can be used to override
272configuration variable commit.status.
273
274--no-status::
275Do not include the output of linkgit:git-status[1] in the
276commit message template when using an editor to prepare the
277default commit message.
278
Junio C Hamano1bb569e2006-05-05 23:14:25279\--::
Junio C Hamano6697ac52006-02-14 08:00:23280Do not interpret any more arguments as options.
281
282<file>...::
Junio C Hamanoe7935c42006-12-13 21:32:17283When files are given on the command line, the command
284commits the contents of the named files, without
285recording the changes already staged. The contents of
286these files are also staged for the next commit on top
287of what have been staged before.
Junio C Hamano1a4e8412005-12-27 08:17:23288
Junio C Hamanoae05fee2010-01-08 07:39:46289:git-commit: 1
290include::date-formats.txt[]
Junio C Hamano1a4e8412005-12-27 08:17:23291
Junio C Hamanoe7935c42006-12-13 21:32:17292EXAMPLES
293--------
294When recording your own work, the contents of modified files in
295your working tree are temporarily stored to a staging area
Junio C Hamano1aa40d22010-01-21 17:46:43296called the "index" with 'git add'. A file can be
Junio C Hamano361c1332007-11-14 12:17:22297reverted back, only in the index but not in the working tree,
Junio C Hamanob76a6862012-05-02 22:02:46298to that of the last commit with `git reset HEAD -- <file>`,
Junio C Hamano1aa40d22010-01-21 17:46:43299which effectively reverts 'git add' and prevents the changes to
Junio C Hamano361c1332007-11-14 12:17:22300this file from participating in the next commit. After building
301the state to be committed incrementally with these commands,
302`git commit` (without any pathname parameter) is used to record what
Junio C Hamanoe7935c42006-12-13 21:32:17303has been staged so far. This is the most basic form of the
304command. An example:
Junio C Hamano40f2f8d2006-02-07 08:04:39305
Junio C Hamanoe7935c42006-12-13 21:32:17306------------
307$ edit hello.c
308$ git rm goodbye.c
309$ git add hello.c
310$ git commit
311------------
Junio C Hamano40f2f8d2006-02-07 08:04:39312
Junio C Hamanoe7935c42006-12-13 21:32:17313Instead of staging files after each individual change, you can
314tell `git commit` to notice the changes to the files whose
315contents are tracked in
316your working tree and do corresponding `git add` and `git rm`
317for you. That is, this example does the same as the earlier
318example if there is no other change in your working tree:
Junio C Hamano40f2f8d2006-02-07 08:04:39319
Junio C Hamanoe7935c42006-12-13 21:32:17320------------
321$ edit hello.c
322$ rm goodbye.c
323$ git commit -a
324------------
Junio C Hamano40f2f8d2006-02-07 08:04:39325
Junio C Hamanoe7935c42006-12-13 21:32:17326The command `git commit -a` first looks at your working tree,
327notices that you have modified hello.c and removed goodbye.c,
328and performs necessary `git add` and `git rm` for you.
Junio C Hamano40f2f8d2006-02-07 08:04:39329
Junio C Hamanoe7935c42006-12-13 21:32:17330After staging changes to many files, you can alter the order the
331changes are recorded in, by giving pathnames to `git commit`.
332When pathnames are given, the command makes a commit that
333only records the changes made to the named paths:
Junio C Hamano40f2f8d2006-02-07 08:04:39334
Junio C Hamanoe7935c42006-12-13 21:32:17335------------
336$ edit hello.c hello.h
337$ git add hello.c hello.h
338$ edit Makefile
339$ git commit Makefile
340------------
Junio C Hamano40f2f8d2006-02-07 08:04:39341
Junio C Hamanoe7935c42006-12-13 21:32:17342This makes a commit that records the modification to `Makefile`.
343The changes staged for `hello.c` and `hello.h` are not included
344in the resulting commit. However, their changes are not lost --
345they are still staged and merely held back. After the above
346sequence, if you do:
Junio C Hamano40f2f8d2006-02-07 08:04:39347
Junio C Hamanoe7935c42006-12-13 21:32:17348------------
349$ git commit
350------------
Junio C Hamano40f2f8d2006-02-07 08:04:39351
Junio C Hamanoe7935c42006-12-13 21:32:17352this second commit would record the changes to `hello.c` and
353`hello.h` as expected.
354
Junio C Hamano1aa40d22010-01-21 17:46:43355After a merge (initiated by 'git merge' or 'git pull') stops
Junio C Hamanofce7c7e2008-07-02 03:06:38356because of conflicts, cleanly merged
Junio C Hamanoe7935c42006-12-13 21:32:17357paths are already staged to be committed for you, and paths that
358conflicted are left in unmerged state. You would have to first
Junio C Hamano1aa40d22010-01-21 17:46:43359check which paths are conflicting with 'git status'
Junio C Hamanoe7935c42006-12-13 21:32:17360and after fixing them manually in your working tree, you would
Junio C Hamano1aa40d22010-01-21 17:46:43361stage the result as usual with 'git add':
Junio C Hamanoe7935c42006-12-13 21:32:17362
363------------
364$ git status | grep unmerged
365unmerged: hello.c
366$ edit hello.c
367$ git add hello.c
368------------
369
370After resolving conflicts and staging the result, `git ls-files -u`
371would stop mentioning the conflicted path. When you are done,
372run `git commit` to finally record the merge:
373
374------------
375$ git commit
376------------
377
378As with the case to record your own changes, you can use `-a`
379option to save typing. One difference is that during a merge
380resolution, you cannot use `git commit` with pathnames to
381alter the order the changes are committed, because the merge
382should be recorded as a single commit. In fact, the command
383refuses to run when given pathnames (but see `-i` option).
384
385
Junio C Hamano775a0f42006-12-31 01:19:14386DISCUSSION
387----------
388
Junio C Hamano8f76dc62007-01-17 07:24:25389Though not required, it's a good idea to begin the commit message
390with a single short (less than 50 character) line summarizing the
391change, followed by a blank line and then a more thorough description.
392Tools that turn commits into email, for example, use the first line
393on the Subject: line and the rest of the commit in the body.
394
Junio C Hamano775a0f42006-12-31 01:19:14395include::i18n.txt[]
396
Junio C Hamanof6002a92007-07-20 10:28:22397ENVIRONMENT AND CONFIGURATION VARIABLES
398---------------------------------------
399The editor used to edit the commit log message will be chosen from the
400GIT_EDITOR environment variable, the core.editor configuration variable, the
401VISUAL environment variable, or the EDITOR environment variable (in that
Junio C Hamano3b70d3c2009-11-21 17:37:37402order). See linkgit:git-var[1] for details.
Junio C Hamanoe7935c42006-12-13 21:32:17403
404HOOKS
405-----
Junio C Hamano26e590a2008-02-17 03:53:51406This command can run `commit-msg`, `prepare-commit-msg`, `pre-commit`,
Junio C Hamanofce7c7e2008-07-02 03:06:38407and `post-commit` hooks. See linkgit:githooks[5] for more
Junio C Hamanoe7935c42006-12-13 21:32:17408information.
409
Junio C Hamano28a85be2012-07-24 22:05:15410FILES
411-----
412
413`$GIT_DIR/COMMIT_EDITMSG`::
414This file contains the commit message of a commit in progress.
415If `git commit` exits due to an error before creating a commit,
416any commit message that has been provided by the user (e.g., in
417an editor session) will be available in this file, but will be
418overwritten by the next invocation of `git commit`.
Junio C Hamanoe7935c42006-12-13 21:32:17419
420SEE ALSO
421--------
Junio C Hamano35738e82008-01-07 07:55:46422linkgit:git-add[1],
423linkgit:git-rm[1],
424linkgit:git-mv[1],
425linkgit:git-merge[1],
426linkgit:git-commit-tree[1]
Junio C Hamano40f2f8d2006-02-07 08:04:39427
Junio C Hamano1a4e8412005-12-27 08:17:23428GIT
429---
Junio C Hamanof7c042d2008-06-06 22:50:53430Part of the linkgit:git[1] suite