1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
\r
4 <article lang="en" id="git-commit(1)">
\r
6 <title>git-commit(1)</title>
\r
8 <primary>git-commit(1)</primary>
\r
11 <simplesect id="_name">
\r
13 <simpara>git-commit - Record changes to the repository</simpara>
\r
15 <simplesect id="_synopsis">
\r
16 <title>SYNOPSIS</title>
\r
18 <literallayout><emphasis>git commit</emphasis> [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend]
\r
19 [--dry-run] [(-c | -C | --fixup | --squash) <commit>]
\r
20 [-F <file> | -m <msg>] [--reset-author] [--allow-empty]
\r
21 [--allow-empty-message] [--no-verify] [-e] [--author=<author>]
\r
22 [--date=<date>] [--cleanup=<mode>] [--status | --no-status]
\r
23 [-i | -o] [--] [<file>…]</literallayout>
\r
26 <simplesect id="_description">
\r
27 <title>DESCRIPTION</title>
\r
28 <simpara>Stores the current contents of the index in a new commit along
\r
29 with a log message from the user describing the changes.</simpara>
\r
30 <simpara>The content to be added can be specified in several ways:</simpara>
\r
31 <orderedlist numeration="arabic">
\r
34 by using <emphasis>git add</emphasis> to incrementally "add" changes to the
\r
35 index before using the <emphasis>commit</emphasis> command (Note: even modified
\r
36 files must be "added");
\r
41 by using <emphasis>git rm</emphasis> to remove files from the working tree
\r
42 and the index, again before using the <emphasis>commit</emphasis> command;
\r
47 by listing files as arguments to the <emphasis>commit</emphasis> command, in which
\r
48 case the commit will ignore changes staged in the index, and instead
\r
49 record the current content of the listed files (which must already
\r
55 by using the -a switch with the <emphasis>commit</emphasis> command to automatically
\r
56 "add" changes from all known files (i.e. all files that are already
\r
57 listed in the index) and to automatically "rm" files in the index
\r
58 that have been removed from the working tree, and then perform the
\r
64 by using the --interactive or --patch switches with the <emphasis>commit</emphasis> command
\r
65 to decide one by one which files or hunks should be part of the commit,
\r
66 before finalizing the operation. See the Interactive Mode section of
\r
67 <xref linkend="git-add(1)" /> to learn how to operate these modes.
\r
71 <simpara>The <emphasis>--dry-run</emphasis> option can be used to obtain a
\r
72 summary of what is included by any of the above for the next
\r
73 commit by giving the same set of parameters (options and paths).</simpara>
\r
74 <simpara>If you make a commit and then find a mistake immediately after
\r
75 that, you can recover from it with <emphasis>git reset</emphasis>.</simpara>
\r
77 <simplesect id="_options">
\r
78 <title>OPTIONS</title>
\r
89 Tell the command to automatically stage files that have
\r
90 been modified and deleted, but new files you have not
\r
91 told git about are not affected.
\r
104 Use the interactive patch selection interface to chose
\r
105 which changes to commit. See <xref linkend="git-add(1)" /> for
\r
115 --reuse-message=<commit>
\r
119 Take an existing commit object, and reuse the log message
\r
120 and the authorship information (including the timestamp)
\r
121 when creating the commit.
\r
130 --reedit-message=<commit>
\r
134 Like <emphasis>-C</emphasis>, but with <emphasis>-c</emphasis> the editor is invoked, so that
\r
135 the user can further edit the commit message.
\r
141 --fixup=<commit>
\r
145 Construct a commit message for use with <emphasis>rebase --autosquash</emphasis>.
\r
146 The commit message will be the subject line from the specified
\r
147 commit with a prefix of "fixup! ". See <xref linkend="git-rebase(1)" />
\r
154 --squash=<commit>
\r
158 Construct a commit message for use with <emphasis>rebase --autosquash</emphasis>.
\r
159 The commit message subject line is taken from the specified
\r
160 commit with a prefix of "squash! ". Can be used with additional
\r
161 commit message options (<emphasis>-m</emphasis>/<emphasis>-c</emphasis>/<emphasis>-C</emphasis>/<emphasis>-F</emphasis>). See
\r
162 <xref linkend="git-rebase(1)" /> for details.
\r
172 When used with -C/-c/--amend options, or when committing after a
\r
173 a conflicting cherry-pick, declare that the authorship of the
\r
174 resulting commit now belongs of the committer. This also renews
\r
175 the author timestamp.
\r
185 When doing a dry-run, give the output in the short-format. See
\r
186 <xref linkend="git-status(1)" /> for details. Implies <emphasis>--dry-run</emphasis>.
\r
196 When doing a dry-run, give the output in a porcelain-ready
\r
197 format. See <xref linkend="git-status(1)" /> for details. Implies
\r
198 <emphasis>--dry-run</emphasis>.
\r
208 When showing <emphasis>short</emphasis> or <emphasis>porcelain</emphasis> status output, terminate
\r
209 entries in the status output with NUL, instead of LF. If no
\r
210 format is given, implies the <emphasis>--porcelain</emphasis> output format.
\r
219 --file=<file>
\r
223 Take the commit message from the given file. Use <emphasis>-</emphasis> to
\r
224 read the message from the standard input.
\r
230 --author=<author>
\r
234 Override the commit author. Specify an explicit author using the
\r
235 standard <emphasis>A U Thor <author@example.com></emphasis> format. Otherwise <author>
\r
236 is assumed to be a pattern and is used to search for an existing
\r
237 commit by that author (i.e. rev-list --all -i --author=<author>);
\r
238 the commit author is then copied from the first such commit found.
\r
244 --date=<date>
\r
248 Override the author date used in the commit.
\r
257 --message=<msg>
\r
261 Use the given <msg> as the commit message.
\r
270 --template=<file>
\r
274 When editing the commit message, start the editor with the
\r
275 contents in the given file. The <emphasis>commit.template</emphasis> configuration
\r
276 variable is often used to give this option implicitly to the
\r
277 command. This mechanism can be used by projects that want to
\r
278 guide participants with some hints on what to write in the message
\r
279 in what order. If the user exits the editor without editing the
\r
280 message, the commit is aborted. This has no effect when a message
\r
281 is given by other means, e.g. with the <emphasis>-m</emphasis> or <emphasis>-F</emphasis> options.
\r
294 Add Signed-off-by line by the committer at the end of the commit
\r
308 This option bypasses the pre-commit and commit-msg hooks.
\r
309 See also <xref linkend="githooks(5)" />.
\r
319 Usually recording a commit that has the exact same tree as its
\r
320 sole parent commit is a mistake, and the command prevents you
\r
321 from making such a commit. This option bypasses the safety, and
\r
322 is primarily for use by foreign SCM interface scripts.
\r
328 --allow-empty-message
\r
332 Like --allow-empty this command is primarily for use by foreign
\r
333 SCM interface scripts. It allows you to create a commit with an
\r
334 empty commit message without using plumbing commands like
\r
335 <xref linkend="git-commit-tree(1)" />.
\r
341 --cleanup=<mode>
\r
345 This option sets how the commit message is cleaned up.
\r
346 The <emphasis><mode></emphasis> can be one of <emphasis>verbatim</emphasis>, <emphasis>whitespace</emphasis>, <emphasis>strip</emphasis>,
\r
347 and <emphasis>default</emphasis>. The <emphasis>default</emphasis> mode will strip leading and
\r
348 trailing empty lines and #commentary from the commit message
\r
349 only if the message is to be edited. Otherwise only whitespace
\r
350 removed. The <emphasis>verbatim</emphasis> mode does not change message at all,
\r
351 <emphasis>whitespace</emphasis> removes just leading/trailing whitespace lines
\r
352 and <emphasis>strip</emphasis> removes both whitespace and commentary.
\r
365 The message taken from file with <emphasis>-F</emphasis>, command line with
\r
366 <emphasis>-m</emphasis>, and from file with <emphasis>-C</emphasis> are usually used as the
\r
367 commit log message unmodified. This option lets you
\r
368 further edit the message taken from these sources.
\r
378 Used to amend the tip of the current branch. Prepare the tree
\r
379 object you would want to replace the latest commit as usual
\r
380 (this includes the usual -i/-o and explicit paths), and the
\r
381 commit log editor is seeded with the commit message from the
\r
382 tip of the current branch. The commit you create replaces the
\r
383 current tip -- if it was a merge, it will have the parents of
\r
384 the current tip as parents -- so the current top commit is
\r
387 <simpara>It is a rough equivalent for:</simpara>
\r
388 <screen> $ git reset --soft HEAD^
\r
389 $ ... do something else to come up with the right tree ...
\r
390 $ git commit -c ORIG_HEAD</screen>
\r
391 <simpara>but can be used to amend a merge commit.</simpara>
\r
392 <simpara>You should understand the implications of rewriting history if you
\r
393 amend a commit that has already been published. (See the "RECOVERING
\r
394 FROM UPSTREAM REBASE" section in <xref linkend="git-rebase(1)" />.)</simpara>
\r
406 Before making a commit out of staged contents so far,
\r
407 stage the contents of paths given on the command line
\r
408 as well. This is usually not what you want unless you
\r
409 are concluding a conflicted merge.
\r
422 Make a commit only from the paths specified on the
\r
423 command line, disregarding any contents that have been
\r
424 staged so far. This is the default mode of operation of
\r
425 <emphasis>git commit</emphasis> if any paths are given on the command line,
\r
426 in which case this option can be omitted.
\r
427 If this option is specified together with <emphasis>--amend</emphasis>, then
\r
428 no paths need to be specified, which can be used to amend
\r
429 the last commit without committing changes that have
\r
430 already been staged.
\r
439 --untracked-files[=<mode>]
\r
443 Show untracked files.
\r
445 <simpara>The mode parameter is optional (defaults to <emphasis>all</emphasis>), and is used to
\r
446 specify the handling of untracked files; when -u is not used, the
\r
447 default is <emphasis>normal</emphasis>, i.e. show untracked files and directories.</simpara>
\r
448 <simpara>The possible options are:</simpara>
\r
452 <emphasis>no</emphasis> - Show no untracked files
\r
457 <emphasis>normal</emphasis> - Shows untracked files and directories
\r
462 <emphasis>all</emphasis> - Also shows individual files in untracked directories.
\r
464 <simpara>The default can be changed using the status.showUntrackedFiles
\r
465 configuration variable documented in <xref linkend="git-config(1)" />.</simpara>
\r
479 Show unified diff between the HEAD commit and what
\r
480 would be committed at the bottom of the commit message
\r
481 template. Note that this diff output doesn't have its
\r
482 lines prefixed with <emphasis>#</emphasis>.
\r
495 Suppress commit summary message.
\r
505 Do not create a commit, but show a list of paths that are
\r
506 to be committed, paths with local changes that will be left
\r
507 uncommitted and paths that are untracked.
\r
517 Include the output of <xref linkend="git-status(1)" /> in the commit
\r
518 message template when using an editor to prepare the commit
\r
519 message. Defaults to on, but can be used to override
\r
520 configuration variable commit.status.
\r
530 Do not include the output of <xref linkend="git-status(1)" /> in the
\r
531 commit message template when using an editor to prepare the
\r
532 default commit message.
\r
542 Do not interpret any more arguments as options.
\r
548 <file>…
\r
552 When files are given on the command line, the command
\r
553 commits the contents of the named files, without
\r
554 recording the changes already staged. The contents of
\r
555 these files are also staged for the next commit on top
\r
556 of what have been staged before.
\r
562 <simplesect id="_date_formats">
\r
563 <title>DATE FORMATS</title>
\r
564 <simpara>The GIT_AUTHOR_DATE, GIT_COMMITTER_DATE environment variables
\r
565 and the <emphasis>--date</emphasis> option
\r
566 support the following date formats:</simpara>
\r
570 Git internal format
\r
574 It is <emphasis><unix timestamp> <timezone offset></emphasis>, where <emphasis><unix
\r
575 timestamp></emphasis> is the number of seconds since the UNIX epoch.
\r
576 <emphasis><timezone offset></emphasis> is a positive or negative offset from UTC.
\r
577 For example CET (which is 2 hours ahead UTC) is <emphasis>+0200</emphasis>.
\r
587 The standard email format as described by RFC 2822, for example
\r
588 <emphasis>Thu, 07 Apr 2005 22:13:13 +0200</emphasis>.
\r
598 Time and date specified by the ISO 8601 standard, for example
\r
599 <emphasis>2005-04-07T22:13:13</emphasis>. The parser accepts a space instead of the
\r
600 <emphasis>T</emphasis> character as well.
\r
602 <note><simpara>In addition, the date part is accepted in the following formats:
\r
603 <emphasis>YYYY.MM.DD</emphasis>, <emphasis>MM/DD/YYYY</emphasis> and <emphasis>DD.MM.YYYY</emphasis>.</simpara></note>
\r
608 <simplesect id="_examples">
\r
609 <title>EXAMPLES</title>
\r
610 <simpara>When recording your own work, the contents of modified files in
\r
611 your working tree are temporarily stored to a staging area
\r
612 called the "index" with <emphasis>git add</emphasis>. A file can be
\r
613 reverted back, only in the index but not in the working tree,
\r
614 to that of the last commit with <emphasis>git reset HEAD -- <file></emphasis>,
\r
615 which effectively reverts <emphasis>git add</emphasis> and prevents the changes to
\r
616 this file from participating in the next commit. After building
\r
617 the state to be committed incrementally with these commands,
\r
618 <emphasis>git commit</emphasis> (without any pathname parameter) is used to record what
\r
619 has been staged so far. This is the most basic form of the
\r
620 command. An example:</simpara>
\r
621 <screen>$ edit hello.c
\r
624 $ git commit</screen>
\r
625 <simpara>Instead of staging files after each individual change, you can
\r
626 tell <emphasis>git commit</emphasis> to notice the changes to the files whose
\r
627 contents are tracked in
\r
628 your working tree and do corresponding <emphasis>git add</emphasis> and <emphasis>git rm</emphasis>
\r
629 for you. That is, this example does the same as the earlier
\r
630 example if there is no other change in your working tree:</simpara>
\r
631 <screen>$ edit hello.c
\r
633 $ git commit -a</screen>
\r
634 <simpara>The command <emphasis>git commit -a</emphasis> first looks at your working tree,
\r
635 notices that you have modified hello.c and removed goodbye.c,
\r
636 and performs necessary <emphasis>git add</emphasis> and <emphasis>git rm</emphasis> for you.</simpara>
\r
637 <simpara>After staging changes to many files, you can alter the order the
\r
638 changes are recorded in, by giving pathnames to <emphasis>git commit</emphasis>.
\r
639 When pathnames are given, the command makes a commit that
\r
640 only records the changes made to the named paths:</simpara>
\r
641 <screen>$ edit hello.c hello.h
\r
642 $ git add hello.c hello.h
\r
644 $ git commit Makefile</screen>
\r
645 <simpara>This makes a commit that records the modification to <emphasis>Makefile</emphasis>.
\r
646 The changes staged for <emphasis>hello.c</emphasis> and <emphasis>hello.h</emphasis> are not included
\r
647 in the resulting commit. However, their changes are not lost --
\r
648 they are still staged and merely held back. After the above
\r
649 sequence, if you do:</simpara>
\r
650 <screen>$ git commit</screen>
\r
651 <simpara>this second commit would record the changes to <emphasis>hello.c</emphasis> and
\r
652 <emphasis>hello.h</emphasis> as expected.</simpara>
\r
653 <simpara>After a merge (initiated by <emphasis>git merge</emphasis> or <emphasis>git pull</emphasis>) stops
\r
654 because of conflicts, cleanly merged
\r
655 paths are already staged to be committed for you, and paths that
\r
656 conflicted are left in unmerged state. You would have to first
\r
657 check which paths are conflicting with <emphasis>git status</emphasis>
\r
658 and after fixing them manually in your working tree, you would
\r
659 stage the result as usual with <emphasis>git add</emphasis>:</simpara>
\r
660 <screen>$ git status | grep unmerged
\r
663 $ git add hello.c</screen>
\r
664 <simpara>After resolving conflicts and staging the result, <emphasis>git ls-files -u</emphasis>
\r
665 would stop mentioning the conflicted path. When you are done,
\r
666 run <emphasis>git commit</emphasis> to finally record the merge:</simpara>
\r
667 <screen>$ git commit</screen>
\r
668 <simpara>As with the case to record your own changes, you can use <emphasis>-a</emphasis>
\r
669 option to save typing. One difference is that during a merge
\r
670 resolution, you cannot use <emphasis>git commit</emphasis> with pathnames to
\r
671 alter the order the changes are committed, because the merge
\r
672 should be recorded as a single commit. In fact, the command
\r
673 refuses to run when given pathnames (but see <emphasis>-i</emphasis> option).</simpara>
\r
675 <simplesect id="_discussion">
\r
676 <title>DISCUSSION</title>
\r
677 <simpara>Though not required, it's a good idea to begin the commit message
\r
678 with a single short (less than 50 character) line summarizing the
\r
679 change, followed by a blank line and then a more thorough description.
\r
680 Tools that turn commits into email, for example, use the first line
\r
681 on the Subject: line and the rest of the commit in the body.</simpara>
\r
682 <simpara>At the core level, git is character encoding agnostic.</simpara>
\r
686 The pathnames recorded in the index and in the tree objects
\r
687 are treated as uninterpreted sequences of non-NUL bytes.
\r
688 What readdir(2) returns are what are recorded and compared
\r
689 with the data git keeps track of, which in turn are expected
\r
690 to be what lstat(2) and creat(2) accepts. There is no such
\r
691 thing as pathname encoding translation.
\r
696 The contents of the blob objects are uninterpreted sequences
\r
697 of bytes. There is no encoding translation at the core
\r
703 The commit log messages are uninterpreted sequences of non-NUL
\r
708 <simpara>Although we encourage that the commit log messages are encoded
\r
709 in UTF-8, both the core and git Porcelain are designed not to
\r
710 force UTF-8 on projects. If all participants of a particular
\r
711 project find it more convenient to use legacy encodings, git
\r
712 does not forbid it. However, there are a few things to keep in
\r
714 <orderedlist numeration="arabic">
\r
717 <emphasis>git commit</emphasis> and <emphasis>git commit-tree</emphasis> issues
\r
718 a warning if the commit log message given to it does not look
\r
719 like a valid UTF-8 string, unless you explicitly say your
\r
720 project uses a legacy encoding. The way to say this is to
\r
721 have i18n.commitencoding in <emphasis>.git/config</emphasis> file, like this:
\r
724 commitencoding = ISO-8859-1</screen>
\r
725 <simpara>Commit objects created with the above setting record the value
\r
726 of <emphasis>i18n.commitencoding</emphasis> in its <emphasis>encoding</emphasis> header. This is to
\r
727 help other people who look at them later. Lack of this header
\r
728 implies that the commit log message is encoded in UTF-8.</simpara>
\r
732 <emphasis>git log</emphasis>, <emphasis>git show</emphasis>, <emphasis>git blame</emphasis> and friends look at the
\r
733 <emphasis>encoding</emphasis> header of a commit object, and try to re-code the
\r
734 log message into UTF-8 unless otherwise specified. You can
\r
735 specify the desired output encoding with
\r
736 <emphasis>i18n.logoutputencoding</emphasis> in <emphasis>.git/config</emphasis> file, like this:
\r
739 logoutputencoding = ISO-8859-1</screen>
\r
740 <simpara>If you do not have this configuration variable, the value of
\r
741 <emphasis>i18n.commitencoding</emphasis> is used instead.</simpara>
\r
744 <simpara>Note that we deliberately chose not to re-code the commit log
\r
745 message when a commit is made to force UTF-8 at the commit
\r
746 object level, because re-coding to UTF-8 is not necessarily a
\r
747 reversible operation.</simpara>
\r
749 <simplesect id="_environment_and_configuration_variables">
\r
750 <title>ENVIRONMENT AND CONFIGURATION VARIABLES</title>
\r
751 <simpara>The editor used to edit the commit log message will be chosen from the
\r
752 GIT_EDITOR environment variable, the core.editor configuration variable, the
\r
753 VISUAL environment variable, or the EDITOR environment variable (in that
\r
754 order). See <xref linkend="git-var(1)" /> for details.</simpara>
\r
756 <simplesect id="_hooks">
\r
757 <title>HOOKS</title>
\r
758 <simpara>This command can run <emphasis>commit-msg</emphasis>, <emphasis>prepare-commit-msg</emphasis>, <emphasis>pre-commit</emphasis>,
\r
759 and <emphasis>post-commit</emphasis> hooks. See <xref linkend="githooks(5)" /> for more
\r
760 information.</simpara>
\r
762 <simplesect id="_see_also">
\r
763 <title>SEE ALSO</title>
\r
764 <simpara><xref linkend="git-add(1)" />,
\r
765 <xref linkend="git-rm(1)" />,
\r
766 <xref linkend="git-mv(1)" />,
\r
767 <xref linkend="git-merge(1)" />,
\r
768 <xref linkend="git-commit-tree(1)" /></simpara>
\r
770 <simplesect id="_git">
\r
772 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
\r