blob: 5cc84a139133dca2fdcb594007c8b0d6464d5ca8 [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,
45 before finalizing the operation. See the ``Interactive Mode`` section of
46 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
104--porcelain::
105When doing a dry-run, give the output in a porcelain-ready
106format. See linkgit:git-status[1] for details. Implies
107`--dry-run`.
108
109-z::
110When showing `short` or `porcelain` status output, terminate
111entries in the status output with NUL, instead of LF. If no
112format is given, implies the `--porcelain` output format.
113
Junio C Hamano1a4e8412005-12-27 08:17:23114-F <file>::
Junio C Hamanoeb415992008-06-08 22:49:47115--file=<file>::
Junio C Hamano1a4e8412005-12-27 08:17:23116Take the commit message from the given file. Use '-' to
117read the message from the standard input.
118
Junio C Hamanoeb415992008-06-08 22:49:47119--author=<author>::
Junio C Hamano13002fb2010-06-08 05:53:58120Override the commit author. Specify an explicit author using the
121standard `A U Thor <author@example.com>` format. Otherwise <author>
122is assumed to be a pattern and is used to search for an existing
123commit by that author (i.e. rev-list --all -i --author=<author>);
124the commit author is then copied from the first such commit found.
Junio C Hamano40f2f8d2006-02-07 08:04:39125
Junio C Hamanoae05fee2010-01-08 07:39:46126--date=<date>::
127Override the author date used in the commit.
128
Junio C Hamanoeb415992008-06-08 22:49:47129-m <msg>::
130--message=<msg>::
Junio C Hamano1a4e8412005-12-27 08:17:23131Use the given <msg> as the commit message.
132
Junio C Hamanoeb415992008-06-08 22:49:47133-t <file>::
134--template=<file>::
Junio C Hamanoa3770f92007-07-25 08:53:33135Use the contents of the given file as the initial version
136of the commit message. The editor is invoked and you can
137make subsequent changes. If a message is specified using
Junio C Hamanob968dbb2007-07-27 07:26:40138the `-m` or `-F` options, this option has no effect. This
139overrides the `commit.template` configuration variable.
Junio C Hamanoa3770f92007-07-25 08:53:33140
Junio C Hamanoeb415992008-06-08 22:49:47141-s::
142--signoff::
Junio C Hamano610d1762008-11-28 06:27:13143Add Signed-off-by line by the committer at the end of the commit
Junio C Hamano7d06a8a2008-10-20 05:42:33144log message.
Junio C Hamano1a4e8412005-12-27 08:17:23145
Junio C Hamanoeb415992008-06-08 22:49:47146-n::
Junio C Hamanoe7935c42006-12-13 21:32:17147--no-verify::
Junio C Hamano942b35e2007-12-09 10:19:33148This option bypasses the pre-commit and commit-msg hooks.
Junio C Hamanofce7c7e2008-07-02 03:06:38149See also linkgit:githooks[5].
Junio C Hamano1a4e8412005-12-27 08:17:23150
Junio C Hamano0c999702007-12-03 09:57:55151--allow-empty::
152Usually recording a commit that has the exact same tree as its
Junio C Hamano58256872007-12-04 08:31:13153sole parent commit is a mistake, and the command prevents you
154from making such a commit. This option bypasses the safety, and
Junio C Hamano619596a2010-08-18 22:15:35155is primarily for use by foreign SCM interface scripts.
Junio C Hamano0c999702007-12-03 09:57:55156
Junio C Hamanocb39aea2010-05-09 07:24:48157--allow-empty-message::
158 Like --allow-empty this command is primarily for use by foreign
Junio C Hamano619596a2010-08-18 22:15:35159 SCM interface scripts. It allows you to create a commit with an
Junio C Hamanocb39aea2010-05-09 07:24:48160 empty commit message without using plumbing commands like
161 linkgit:git-commit-tree[1].
162
Junio C Hamano554da792007-12-27 03:29:58163--cleanup=<mode>::
164This option sets how the commit message is cleaned up.
165The '<mode>' can be one of 'verbatim', 'whitespace', 'strip',
166and 'default'. The 'default' mode will strip leading and
167trailing empty lines and #commentary from the commit message
168only if the message is to be edited. Otherwise only whitespace
169removed. The 'verbatim' mode does not change message at all,
170'whitespace' removes just leading/trailing whitespace lines
171and 'strip' removes both whitespace and commentary.
172
Junio C Hamanoeb415992008-06-08 22:49:47173-e::
174--edit::
Junio C Hamano1a4e8412005-12-27 08:17:23175The message taken from file with `-F`, command line with
176`-m`, and from file with `-C` are usually used as the
177commit log message unmodified. This option lets you
178further edit the message taken from these sources.
179
Junio C Hamanobfe9e752006-04-05 21:43:28180--amend::
Junio C Hamanobfe9e752006-04-05 21:43:28181Used to amend the tip of the current branch. Prepare the tree
182object you would want to replace the latest commit as usual
183(this includes the usual -i/-o and explicit paths), and the
184commit log editor is seeded with the commit message from the
185tip of the current branch. The commit you create replaces the
186current tip -- if it was a merge, it will have the parents of
187the current tip as parents -- so the current top commit is
188discarded.
189+
Junio C Hamano47ea30e2006-04-05 23:08:03190--
Junio C Hamanobfe9e752006-04-05 21:43:28191It is a rough equivalent for:
Junio C Hamano47ea30e2006-04-05 23:08:03192------
Junio C Hamanobfe9e752006-04-05 21:43:28193$ git reset --soft HEAD^
194$ ... do something else to come up with the right tree ...
195$ git commit -c ORIG_HEAD
Junio C Hamano47ea30e2006-04-05 23:08:03196
197------
Junio C Hamanobfe9e752006-04-05 21:43:28198but can be used to amend a merge commit.
Junio C Hamano47ea30e2006-04-05 23:08:03199--
Junio C Hamano7d06a8a2008-10-20 05:42:33200+
201You should understand the implications of rewriting history if you
202amend a commit that has already been published. (See the "RECOVERING
203FROM UPSTREAM REBASE" section in linkgit:git-rebase[1].)
Junio C Hamanobfe9e752006-04-05 21:43:28204
Junio C Hamanoeb415992008-06-08 22:49:47205-i::
206--include::
Junio C Hamanoe7935c42006-12-13 21:32:17207Before making a commit out of staged contents so far,
208stage the contents of paths given on the command line
209as well. This is usually not what you want unless you
210are concluding a conflicted merge.
Junio C Hamano1a4e8412005-12-27 08:17:23211
Junio C Hamanoeb415992008-06-08 22:49:47212-o::
213--only::
Junio C Hamanoe79159d2008-04-12 08:23:17214Make a commit only from the paths specified on the
215command line, disregarding any contents that have been
216staged so far. This is the default mode of operation of
Junio C Hamano1aa40d22010-01-21 17:46:43217'git commit' if any paths are given on the command line,
Junio C Hamanoe79159d2008-04-12 08:23:17218in which case this option can be omitted.
219If this option is specified together with '--amend', then
Junio C Hamano54bf1e22008-12-20 06:30:11220no paths need to be specified, which can be used to amend
Junio C Hamanoe79159d2008-04-12 08:23:17221the last commit without committing changes that have
222already been staged.
223
Junio C Hamano4224f992008-06-23 07:14:08224-u[<mode>]::
225--untracked-files[=<mode>]::
Junio C Hamano36a4dbc2011-02-22 07:51:32226Show untracked files.
Junio C Hamano4224f992008-06-23 07:14:08227+
Junio C Hamano36a4dbc2011-02-22 07:51:32228The mode parameter is optional (defaults to 'all'), and is used to
229specify the handling of untracked files; when -u is not used, the
230default is 'normal', i.e. show untracked files and directories.
Junio C Hamano4224f992008-06-23 07:14:08231+
Junio C Hamanoe1cca182010-02-20 20:01:23232The possible options are:
233+
Junio C Hamano4224f992008-06-23 07:14:08234- 'no' - Show no untracked files
235- 'normal' - Shows untracked files and directories
236- 'all' - Also shows individual files in untracked directories.
Junio C Hamano4224f992008-06-23 07:14:08237+
Junio C Hamano36a4dbc2011-02-22 07:51:32238The default can be changed using the status.showUntrackedFiles
239configuration variable documented in linkgit:git-config[1].
Junio C Hamano1e6e0062007-07-13 05:33:25240
Junio C Hamanoeb415992008-06-08 22:49:47241-v::
242--verbose::
Junio C Hamano1e6e0062007-07-13 05:33:25243Show unified diff between the HEAD commit and what
244would be committed at the bottom of the commit message
245template. Note that this diff output doesn't have its
246lines prefixed with '#'.
247
Junio C Hamanoeb415992008-06-08 22:49:47248-q::
249--quiet::
Junio C Hamanof9771f62007-01-17 17:42:30250Suppress commit summary message.
Junio C Hamano7d23f5e2006-12-16 07:44:04251
Junio C Hamano1bb31992009-08-29 04:24:08252--dry-run::
253Do not create a commit, but show a list of paths that are
254to be committed, paths with local changes that will be left
255uncommitted and paths that are untracked.
256
Junio C Hamano6ce6b6c2010-01-18 01:25:50257--status::
258Include the output of linkgit:git-status[1] in the commit
259message template when using an editor to prepare the commit
260message. Defaults to on, but can be used to override
261configuration variable commit.status.
262
263--no-status::
264Do not include the output of linkgit:git-status[1] in the
265commit message template when using an editor to prepare the
266default commit message.
267
Junio C Hamano1bb569e2006-05-05 23:14:25268\--::
Junio C Hamano6697ac52006-02-14 08:00:23269Do not interpret any more arguments as options.
270
271<file>...::
Junio C Hamanoe7935c42006-12-13 21:32:17272When files are given on the command line, the command
273commits the contents of the named files, without
274recording the changes already staged. The contents of
275these files are also staged for the next commit on top
276of what have been staged before.
Junio C Hamano1a4e8412005-12-27 08:17:23277
Junio C Hamanoae05fee2010-01-08 07:39:46278:git-commit: 1
279include::date-formats.txt[]
Junio C Hamano1a4e8412005-12-27 08:17:23280
Junio C Hamanoe7935c42006-12-13 21:32:17281EXAMPLES
282--------
283When recording your own work, the contents of modified files in
284your working tree are temporarily stored to a staging area
Junio C Hamano1aa40d22010-01-21 17:46:43285called the "index" with 'git add'. A file can be
Junio C Hamano361c1332007-11-14 12:17:22286reverted back, only in the index but not in the working tree,
Junio C Hamano360e3a12011-07-13 23:51:56287to that of the last commit with `git reset HEAD \-- <file>`,
Junio C Hamano1aa40d22010-01-21 17:46:43288which effectively reverts 'git add' and prevents the changes to
Junio C Hamano361c1332007-11-14 12:17:22289this file from participating in the next commit. After building
290the state to be committed incrementally with these commands,
291`git commit` (without any pathname parameter) is used to record what
Junio C Hamanoe7935c42006-12-13 21:32:17292has been staged so far. This is the most basic form of the
293command. An example:
Junio C Hamano40f2f8d2006-02-07 08:04:39294
Junio C Hamanoe7935c42006-12-13 21:32:17295------------
296$ edit hello.c
297$ git rm goodbye.c
298$ git add hello.c
299$ git commit
300------------
Junio C Hamano40f2f8d2006-02-07 08:04:39301
Junio C Hamanoe7935c42006-12-13 21:32:17302Instead of staging files after each individual change, you can
303tell `git commit` to notice the changes to the files whose
304contents are tracked in
305your working tree and do corresponding `git add` and `git rm`
306for you. That is, this example does the same as the earlier
307example if there is no other change in your working tree:
Junio C Hamano40f2f8d2006-02-07 08:04:39308
Junio C Hamanoe7935c42006-12-13 21:32:17309------------
310$ edit hello.c
311$ rm goodbye.c
312$ git commit -a
313------------
Junio C Hamano40f2f8d2006-02-07 08:04:39314
Junio C Hamanoe7935c42006-12-13 21:32:17315The command `git commit -a` first looks at your working tree,
316notices that you have modified hello.c and removed goodbye.c,
317and performs necessary `git add` and `git rm` for you.
Junio C Hamano40f2f8d2006-02-07 08:04:39318
Junio C Hamanoe7935c42006-12-13 21:32:17319After staging changes to many files, you can alter the order the
320changes are recorded in, by giving pathnames to `git commit`.
321When pathnames are given, the command makes a commit that
322only records the changes made to the named paths:
Junio C Hamano40f2f8d2006-02-07 08:04:39323
Junio C Hamanoe7935c42006-12-13 21:32:17324------------
325$ edit hello.c hello.h
326$ git add hello.c hello.h
327$ edit Makefile
328$ git commit Makefile
329------------
Junio C Hamano40f2f8d2006-02-07 08:04:39330
Junio C Hamanoe7935c42006-12-13 21:32:17331This makes a commit that records the modification to `Makefile`.
332The changes staged for `hello.c` and `hello.h` are not included
333in the resulting commit. However, their changes are not lost --
334they are still staged and merely held back. After the above
335sequence, if you do:
Junio C Hamano40f2f8d2006-02-07 08:04:39336
Junio C Hamanoe7935c42006-12-13 21:32:17337------------
338$ git commit
339------------
Junio C Hamano40f2f8d2006-02-07 08:04:39340
Junio C Hamanoe7935c42006-12-13 21:32:17341this second commit would record the changes to `hello.c` and
342`hello.h` as expected.
343
Junio C Hamano1aa40d22010-01-21 17:46:43344After a merge (initiated by 'git merge' or 'git pull') stops
Junio C Hamanofce7c7e2008-07-02 03:06:38345because of conflicts, cleanly merged
Junio C Hamanoe7935c42006-12-13 21:32:17346paths are already staged to be committed for you, and paths that
347conflicted are left in unmerged state. You would have to first
Junio C Hamano1aa40d22010-01-21 17:46:43348check which paths are conflicting with 'git status'
Junio C Hamanoe7935c42006-12-13 21:32:17349and after fixing them manually in your working tree, you would
Junio C Hamano1aa40d22010-01-21 17:46:43350stage the result as usual with 'git add':
Junio C Hamanoe7935c42006-12-13 21:32:17351
352------------
353$ git status | grep unmerged
354unmerged: hello.c
355$ edit hello.c
356$ git add hello.c
357------------
358
359After resolving conflicts and staging the result, `git ls-files -u`
360would stop mentioning the conflicted path. When you are done,
361run `git commit` to finally record the merge:
362
363------------
364$ git commit
365------------
366
367As with the case to record your own changes, you can use `-a`
368option to save typing. One difference is that during a merge
369resolution, you cannot use `git commit` with pathnames to
370alter the order the changes are committed, because the merge
371should be recorded as a single commit. In fact, the command
372refuses to run when given pathnames (but see `-i` option).
373
374
Junio C Hamano775a0f42006-12-31 01:19:14375DISCUSSION
376----------
377
Junio C Hamano8f76dc62007-01-17 07:24:25378Though not required, it's a good idea to begin the commit message
379with a single short (less than 50 character) line summarizing the
380change, followed by a blank line and then a more thorough description.
381Tools that turn commits into email, for example, use the first line
382on the Subject: line and the rest of the commit in the body.
383
Junio C Hamano775a0f42006-12-31 01:19:14384include::i18n.txt[]
385
Junio C Hamanof6002a92007-07-20 10:28:22386ENVIRONMENT AND CONFIGURATION VARIABLES
387---------------------------------------
388The editor used to edit the commit log message will be chosen from the
389GIT_EDITOR environment variable, the core.editor configuration variable, the
390VISUAL environment variable, or the EDITOR environment variable (in that
Junio C Hamano3b70d3c2009-11-21 17:37:37391order). See linkgit:git-var[1] for details.
Junio C Hamanoe7935c42006-12-13 21:32:17392
393HOOKS
394-----
Junio C Hamano26e590a2008-02-17 03:53:51395This command can run `commit-msg`, `prepare-commit-msg`, `pre-commit`,
Junio C Hamanofce7c7e2008-07-02 03:06:38396and `post-commit` hooks. See linkgit:githooks[5] for more
Junio C Hamanoe7935c42006-12-13 21:32:17397information.
398
399
400SEE ALSO
401--------
Junio C Hamano35738e82008-01-07 07:55:46402linkgit:git-add[1],
403linkgit:git-rm[1],
404linkgit:git-mv[1],
405linkgit:git-merge[1],
406linkgit:git-commit-tree[1]
Junio C Hamano40f2f8d2006-02-07 08:04:39407
Junio C Hamano1a4e8412005-12-27 08:17:23408GIT
409---
Junio C Hamanof7c042d2008-06-06 22:50:53410Part of the linkgit:git[1] suite