1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <!DOCTYPE sect2 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
\r
4 <sect2 lang="en" id="git-commit(1)">
\r
5 <title>git-commit(1)</title>
\r
7 <primary>git-commit(1)</primary>
\r
9 <simplesect id="git-commit(1)__name">
\r
11 <simpara>git-commit - Record changes to the repository</simpara>
\r
13 <simplesect id="git-commit(1)__synopsis">
\r
14 <title>SYNOPSIS</title>
\r
16 <literallayout><emphasis>git commit</emphasis> [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend]
\r
17 [--dry-run] [(-c | -C | --fixup | --squash) <commit>]
\r
18 [-F <file> | -m <msg>] [--reset-author] [--allow-empty]
\r
19 [--allow-empty-message] [--no-verify] [-e] [--author=<author>]
\r
20 [--date=<date>] [--cleanup=<mode>] [--status | --no-status]
\r
21 [-i | -o] [-S[<keyid>]] [--] [<file>…]</literallayout>
\r
24 <simplesect id="git-commit(1)__description">
\r
25 <title>DESCRIPTION</title>
\r
26 <simpara>Stores the current contents of the index in a new commit along
\r
27 with a log message from the user describing the changes.</simpara>
\r
28 <simpara>The content to be added can be specified in several ways:</simpara>
\r
29 <orderedlist numeration="arabic">
\r
32 by using <emphasis>git add</emphasis> to incrementally "add" changes to the
\r
33 index before using the <emphasis>commit</emphasis> command (Note: even modified
\r
34 files must be "added");
\r
39 by using <emphasis>git rm</emphasis> to remove files from the working tree
\r
40 and the index, again before using the <emphasis>commit</emphasis> command;
\r
45 by listing files as arguments to the <emphasis>commit</emphasis> command, in which
\r
46 case the commit will ignore changes staged in the index, and instead
\r
47 record the current content of the listed files (which must already
\r
53 by using the -a switch with the <emphasis>commit</emphasis> command to automatically
\r
54 "add" changes from all known files (i.e. all files that are already
\r
55 listed in the index) and to automatically "rm" files in the index
\r
56 that have been removed from the working tree, and then perform the
\r
62 by using the --interactive or --patch switches with the <emphasis>commit</emphasis> command
\r
63 to decide one by one which files or hunks should be part of the commit,
\r
64 before finalizing the operation. See the Interactive Mode section of
\r
65 <xref linkend="git-add(1)" /> to learn how to operate these modes.
\r
69 <simpara>The <emphasis>--dry-run</emphasis> option can be used to obtain a
\r
70 summary of what is included by any of the above for the next
\r
71 commit by giving the same set of parameters (options and paths).</simpara>
\r
72 <simpara>If you make a commit and then find a mistake immediately after
\r
73 that, you can recover from it with <emphasis>git reset</emphasis>.</simpara>
\r
75 <simplesect id="git-commit(1)__options">
\r
76 <title>OPTIONS</title>
\r
87 Tell the command to automatically stage files that have
\r
88 been modified and deleted, but new files you have not
\r
89 told git about are not affected.
\r
102 Use the interactive patch selection interface to chose
\r
103 which changes to commit. See <xref linkend="git-add(1)" /> for
\r
113 --reuse-message=<commit>
\r
117 Take an existing commit object, and reuse the log message
\r
118 and the authorship information (including the timestamp)
\r
119 when creating the commit.
\r
128 --reedit-message=<commit>
\r
132 Like <emphasis>-C</emphasis>, but with <emphasis>-c</emphasis> the editor is invoked, so that
\r
133 the user can further edit the commit message.
\r
139 --fixup=<commit>
\r
143 Construct a commit message for use with <emphasis>rebase --autosquash</emphasis>.
\r
144 The commit message will be the subject line from the specified
\r
145 commit with a prefix of "fixup! ". See <xref linkend="git-rebase(1)" />
\r
152 --squash=<commit>
\r
156 Construct a commit message for use with <emphasis>rebase --autosquash</emphasis>.
\r
157 The commit message subject line is taken from the specified
\r
158 commit with a prefix of "squash! ". Can be used with additional
\r
159 commit message options (<emphasis>-m</emphasis>/<emphasis>-c</emphasis>/<emphasis>-C</emphasis>/<emphasis>-F</emphasis>). See
\r
160 <xref linkend="git-rebase(1)" /> for details.
\r
170 When used with -C/-c/--amend options, or when committing after a
\r
171 a conflicting cherry-pick, declare that the authorship of the
\r
172 resulting commit now belongs of the committer. This also renews
\r
173 the author timestamp.
\r
183 When doing a dry-run, give the output in the short-format. See
\r
184 <xref linkend="git-status(1)" /> for details. Implies <emphasis>--dry-run</emphasis>.
\r
194 Show the branch and tracking info even in short-format.
\r
204 When doing a dry-run, give the output in a porcelain-ready
\r
205 format. See <xref linkend="git-status(1)" /> for details. Implies
\r
206 <emphasis>--dry-run</emphasis>.
\r
216 When doing a dry-run, give the output in a the long-format.
\r
217 Implies <emphasis>--dry-run</emphasis>.
\r
230 When showing <emphasis>short</emphasis> or <emphasis>porcelain</emphasis> status output, terminate
\r
231 entries in the status output with NUL, instead of LF. If no
\r
232 format is given, implies the <emphasis>--porcelain</emphasis> output format.
\r
241 --file=<file>
\r
245 Take the commit message from the given file. Use <emphasis>-</emphasis> to
\r
246 read the message from the standard input.
\r
252 --author=<author>
\r
256 Override the commit author. Specify an explicit author using the
\r
257 standard <emphasis>A U Thor <author@example.com></emphasis> format. Otherwise <author>
\r
258 is assumed to be a pattern and is used to search for an existing
\r
259 commit by that author (i.e. rev-list --all -i --author=<author>);
\r
260 the commit author is then copied from the first such commit found.
\r
266 --date=<date>
\r
270 Override the author date used in the commit.
\r
279 --message=<msg>
\r
283 Use the given <msg> as the commit message.
\r
292 --template=<file>
\r
296 When editing the commit message, start the editor with the
\r
297 contents in the given file. The <emphasis>commit.template</emphasis> configuration
\r
298 variable is often used to give this option implicitly to the
\r
299 command. This mechanism can be used by projects that want to
\r
300 guide participants with some hints on what to write in the message
\r
301 in what order. If the user exits the editor without editing the
\r
302 message, the commit is aborted. This has no effect when a message
\r
303 is given by other means, e.g. with the <emphasis>-m</emphasis> or <emphasis>-F</emphasis> options.
\r
316 Add Signed-off-by line by the committer at the end of the commit
\r
330 This option bypasses the pre-commit and commit-msg hooks.
\r
331 See also <xref linkend="githooks(5)" />.
\r
341 Usually recording a commit that has the exact same tree as its
\r
342 sole parent commit is a mistake, and the command prevents you
\r
343 from making such a commit. This option bypasses the safety, and
\r
344 is primarily for use by foreign SCM interface scripts.
\r
350 --allow-empty-message
\r
354 Like --allow-empty this command is primarily for use by foreign
\r
355 SCM interface scripts. It allows you to create a commit with an
\r
356 empty commit message without using plumbing commands like
\r
357 <xref linkend="git-commit-tree(1)" />.
\r
363 --cleanup=<mode>
\r
367 This option sets how the commit message is cleaned up.
\r
368 The <emphasis><mode></emphasis> can be one of <emphasis>verbatim</emphasis>, <emphasis>whitespace</emphasis>, <emphasis>strip</emphasis>,
\r
369 and <emphasis>default</emphasis>. The <emphasis>default</emphasis> mode will strip leading and
\r
370 trailing empty lines and #commentary from the commit message
\r
371 only if the message is to be edited. Otherwise only whitespace
\r
372 removed. The <emphasis>verbatim</emphasis> mode does not change message at all,
\r
373 <emphasis>whitespace</emphasis> removes just leading/trailing whitespace lines
\r
374 and <emphasis>strip</emphasis> removes both whitespace and commentary.
\r
387 The message taken from file with <emphasis>-F</emphasis>, command line with
\r
388 <emphasis>-m</emphasis>, and from file with <emphasis>-C</emphasis> are usually used as the
\r
389 commit log message unmodified. This option lets you
\r
390 further edit the message taken from these sources.
\r
400 Use the selected commit message without launching an editor.
\r
401 For example, <emphasis>git commit --amend --no-edit</emphasis> amends a commit
\r
402 without changing its commit message.
\r
412 Used to amend the tip of the current branch. Prepare the tree
\r
413 object you would want to replace the latest commit as usual
\r
414 (this includes the usual -i/-o and explicit paths), and the
\r
415 commit log editor is seeded with the commit message from the
\r
416 tip of the current branch. The commit you create replaces the
\r
417 current tip -- if it was a merge, it will have the parents of
\r
418 the current tip as parents -- so the current top commit is
\r
421 <simpara>It is a rough equivalent for:</simpara>
\r
422 <screen> $ git reset --soft HEAD^
\r
423 $ ... do something else to come up with the right tree ...
\r
424 $ git commit -c ORIG_HEAD</screen>
\r
425 <simpara>but can be used to amend a merge commit.</simpara>
\r
426 <simpara>You should understand the implications of rewriting history if you
\r
427 amend a commit that has already been published. (See the "RECOVERING
\r
428 FROM UPSTREAM REBASE" section in <xref linkend="git-rebase(1)" />.)</simpara>
\r
437 Bypass the post-rewrite hook.
\r
450 Before making a commit out of staged contents so far,
\r
451 stage the contents of paths given on the command line
\r
452 as well. This is usually not what you want unless you
\r
453 are concluding a conflicted merge.
\r
466 Make a commit only from the paths specified on the
\r
467 command line, disregarding any contents that have been
\r
468 staged so far. This is the default mode of operation of
\r
469 <emphasis>git commit</emphasis> if any paths are given on the command line,
\r
470 in which case this option can be omitted.
\r
471 If this option is specified together with <emphasis>--amend</emphasis>, then
\r
472 no paths need to be specified, which can be used to amend
\r
473 the last commit without committing changes that have
\r
474 already been staged.
\r
483 --untracked-files[=<mode>]
\r
487 Show untracked files.
\r
489 <simpara>The mode parameter is optional (defaults to <emphasis>all</emphasis>), and is used to
\r
490 specify the handling of untracked files; when -u is not used, the
\r
491 default is <emphasis>normal</emphasis>, i.e. show untracked files and directories.</simpara>
\r
492 <simpara>The possible options are:</simpara>
\r
496 <emphasis>no</emphasis> - Show no untracked files
\r
501 <emphasis>normal</emphasis> - Shows untracked files and directories
\r
506 <emphasis>all</emphasis> - Also shows individual files in untracked directories.
\r
508 <simpara>The default can be changed using the status.showUntrackedFiles
\r
509 configuration variable documented in <xref linkend="git-config(1)" />.</simpara>
\r
523 Show unified diff between the HEAD commit and what
\r
524 would be committed at the bottom of the commit message
\r
525 template. Note that this diff output doesn't have its
\r
526 lines prefixed with <emphasis>#</emphasis>.
\r
539 Suppress commit summary message.
\r
549 Do not create a commit, but show a list of paths that are
\r
550 to be committed, paths with local changes that will be left
\r
551 uncommitted and paths that are untracked.
\r
561 Include the output of <xref linkend="git-status(1)" /> in the commit
\r
562 message template when using an editor to prepare the commit
\r
563 message. Defaults to on, but can be used to override
\r
564 configuration variable commit.status.
\r
574 Do not include the output of <xref linkend="git-status(1)" /> in the
\r
575 commit message template when using an editor to prepare the
\r
576 default commit message.
\r
585 --gpg-sign[=<keyid>]
\r
599 Do not interpret any more arguments as options.
\r
605 <file>…
\r
609 When files are given on the command line, the command
\r
610 commits the contents of the named files, without
\r
611 recording the changes already staged. The contents of
\r
612 these files are also staged for the next commit on top
\r
613 of what have been staged before.
\r
619 <simplesect id="git-commit(1)__date_formats">
\r
620 <title>DATE FORMATS</title>
\r
621 <simpara>The GIT_AUTHOR_DATE, GIT_COMMITTER_DATE environment variables
\r
622 and the <emphasis>--date</emphasis> option
\r
623 support the following date formats:</simpara>
\r
627 Git internal format
\r
631 It is <emphasis><unix timestamp> <timezone offset></emphasis>, where <emphasis><unix
\r
632 timestamp></emphasis> is the number of seconds since the UNIX epoch.
\r
633 <emphasis><timezone offset></emphasis> is a positive or negative offset from UTC.
\r
634 For example CET (which is 2 hours ahead UTC) is <emphasis>+0200</emphasis>.
\r
644 The standard email format as described by RFC 2822, for example
\r
645 <emphasis>Thu, 07 Apr 2005 22:13:13 +0200</emphasis>.
\r
655 Time and date specified by the ISO 8601 standard, for example
\r
656 <emphasis>2005-04-07T22:13:13</emphasis>. The parser accepts a space instead of the
\r
657 <emphasis>T</emphasis> character as well.
\r
659 <note><simpara>In addition, the date part is accepted in the following formats:
\r
660 <emphasis>YYYY.MM.DD</emphasis>, <emphasis>MM/DD/YYYY</emphasis> and <emphasis>DD.MM.YYYY</emphasis>.</simpara></note>
\r
665 <simplesect id="git-commit(1)__examples">
\r
666 <title>EXAMPLES</title>
\r
667 <simpara>When recording your own work, the contents of modified files in
\r
668 your working tree are temporarily stored to a staging area
\r
669 called the "index" with <emphasis>git add</emphasis>. A file can be
\r
670 reverted back, only in the index but not in the working tree,
\r
671 to that of the last commit with <emphasis>git reset HEAD -- <file></emphasis>,
\r
672 which effectively reverts <emphasis>git add</emphasis> and prevents the changes to
\r
673 this file from participating in the next commit. After building
\r
674 the state to be committed incrementally with these commands,
\r
675 <emphasis>git commit</emphasis> (without any pathname parameter) is used to record what
\r
676 has been staged so far. This is the most basic form of the
\r
677 command. An example:</simpara>
\r
678 <screen>$ edit hello.c
\r
681 $ git commit</screen>
\r
682 <simpara>Instead of staging files after each individual change, you can
\r
683 tell <emphasis>git commit</emphasis> to notice the changes to the files whose
\r
684 contents are tracked in
\r
685 your working tree and do corresponding <emphasis>git add</emphasis> and <emphasis>git rm</emphasis>
\r
686 for you. That is, this example does the same as the earlier
\r
687 example if there is no other change in your working tree:</simpara>
\r
688 <screen>$ edit hello.c
\r
690 $ git commit -a</screen>
\r
691 <simpara>The command <emphasis>git commit -a</emphasis> first looks at your working tree,
\r
692 notices that you have modified hello.c and removed goodbye.c,
\r
693 and performs necessary <emphasis>git add</emphasis> and <emphasis>git rm</emphasis> for you.</simpara>
\r
694 <simpara>After staging changes to many files, you can alter the order the
\r
695 changes are recorded in, by giving pathnames to <emphasis>git commit</emphasis>.
\r
696 When pathnames are given, the command makes a commit that
\r
697 only records the changes made to the named paths:</simpara>
\r
698 <screen>$ edit hello.c hello.h
\r
699 $ git add hello.c hello.h
\r
701 $ git commit Makefile</screen>
\r
702 <simpara>This makes a commit that records the modification to <emphasis>Makefile</emphasis>.
\r
703 The changes staged for <emphasis>hello.c</emphasis> and <emphasis>hello.h</emphasis> are not included
\r
704 in the resulting commit. However, their changes are not lost --
\r
705 they are still staged and merely held back. After the above
\r
706 sequence, if you do:</simpara>
\r
707 <screen>$ git commit</screen>
\r
708 <simpara>this second commit would record the changes to <emphasis>hello.c</emphasis> and
\r
709 <emphasis>hello.h</emphasis> as expected.</simpara>
\r
710 <simpara>After a merge (initiated by <emphasis>git merge</emphasis> or <emphasis>git pull</emphasis>) stops
\r
711 because of conflicts, cleanly merged
\r
712 paths are already staged to be committed for you, and paths that
\r
713 conflicted are left in unmerged state. You would have to first
\r
714 check which paths are conflicting with <emphasis>git status</emphasis>
\r
715 and after fixing them manually in your working tree, you would
\r
716 stage the result as usual with <emphasis>git add</emphasis>:</simpara>
\r
717 <screen>$ git status | grep unmerged
\r
720 $ git add hello.c</screen>
\r
721 <simpara>After resolving conflicts and staging the result, <emphasis>git ls-files -u</emphasis>
\r
722 would stop mentioning the conflicted path. When you are done,
\r
723 run <emphasis>git commit</emphasis> to finally record the merge:</simpara>
\r
724 <screen>$ git commit</screen>
\r
725 <simpara>As with the case to record your own changes, you can use <emphasis>-a</emphasis>
\r
726 option to save typing. One difference is that during a merge
\r
727 resolution, you cannot use <emphasis>git commit</emphasis> with pathnames to
\r
728 alter the order the changes are committed, because the merge
\r
729 should be recorded as a single commit. In fact, the command
\r
730 refuses to run when given pathnames (but see <emphasis>-i</emphasis> option).</simpara>
\r
732 <simplesect id="git-commit(1)__discussion">
\r
733 <title>DISCUSSION</title>
\r
734 <simpara>Though not required, it's a good idea to begin the commit message
\r
735 with a single short (less than 50 character) line summarizing the
\r
736 change, followed by a blank line and then a more thorough description.
\r
737 The text up to the first blank line in a commit message is treated
\r
738 as the commit title, and that title is used throughout git.
\r
739 For example, <xref linkend="git-format-patch(1)" /> turns a commit into email, and it uses
\r
740 the title on the Subject line and the rest of the commit in the body.</simpara>
\r
741 <simpara>At the core level, git is character encoding agnostic.</simpara>
\r
745 The pathnames recorded in the index and in the tree objects
\r
746 are treated as uninterpreted sequences of non-NUL bytes.
\r
747 What readdir(2) returns are what are recorded and compared
\r
748 with the data git keeps track of, which in turn are expected
\r
749 to be what lstat(2) and creat(2) accepts. There is no such
\r
750 thing as pathname encoding translation.
\r
755 The contents of the blob objects are uninterpreted sequences
\r
756 of bytes. There is no encoding translation at the core
\r
762 The commit log messages are uninterpreted sequences of non-NUL
\r
767 <simpara>Although we encourage that the commit log messages are encoded
\r
768 in UTF-8, both the core and git Porcelain are designed not to
\r
769 force UTF-8 on projects. If all participants of a particular
\r
770 project find it more convenient to use legacy encodings, git
\r
771 does not forbid it. However, there are a few things to keep in
\r
773 <orderedlist numeration="arabic">
\r
776 <emphasis>git commit</emphasis> and <emphasis>git commit-tree</emphasis> issues
\r
777 a warning if the commit log message given to it does not look
\r
778 like a valid UTF-8 string, unless you explicitly say your
\r
779 project uses a legacy encoding. The way to say this is to
\r
780 have i18n.commitencoding in <emphasis>.git/config</emphasis> file, like this:
\r
783 commitencoding = ISO-8859-1</screen>
\r
784 <simpara>Commit objects created with the above setting record the value
\r
785 of <emphasis>i18n.commitencoding</emphasis> in its <emphasis>encoding</emphasis> header. This is to
\r
786 help other people who look at them later. Lack of this header
\r
787 implies that the commit log message is encoded in UTF-8.</simpara>
\r
791 <emphasis>git log</emphasis>, <emphasis>git show</emphasis>, <emphasis>git blame</emphasis> and friends look at the
\r
792 <emphasis>encoding</emphasis> header of a commit object, and try to re-code the
\r
793 log message into UTF-8 unless otherwise specified. You can
\r
794 specify the desired output encoding with
\r
795 <emphasis>i18n.logoutputencoding</emphasis> in <emphasis>.git/config</emphasis> file, like this:
\r
798 logoutputencoding = ISO-8859-1</screen>
\r
799 <simpara>If you do not have this configuration variable, the value of
\r
800 <emphasis>i18n.commitencoding</emphasis> is used instead.</simpara>
\r
803 <simpara>Note that we deliberately chose not to re-code the commit log
\r
804 message when a commit is made to force UTF-8 at the commit
\r
805 object level, because re-coding to UTF-8 is not necessarily a
\r
806 reversible operation.</simpara>
\r
808 <simplesect id="git-commit(1)__environment_and_configuration_variables">
\r
809 <title>ENVIRONMENT AND CONFIGURATION VARIABLES</title>
\r
810 <simpara>The editor used to edit the commit log message will be chosen from the
\r
811 GIT_EDITOR environment variable, the core.editor configuration variable, the
\r
812 VISUAL environment variable, or the EDITOR environment variable (in that
\r
813 order). See <xref linkend="git-var(1)" /> for details.</simpara>
\r
815 <simplesect id="git-commit(1)__hooks">
\r
816 <title>HOOKS</title>
\r
817 <simpara>This command can run <emphasis>commit-msg</emphasis>, <emphasis>prepare-commit-msg</emphasis>, <emphasis>pre-commit</emphasis>,
\r
818 and <emphasis>post-commit</emphasis> hooks. See <xref linkend="githooks(5)" /> for more
\r
819 information.</simpara>
\r
821 <simplesect id="git-commit(1)__files">
\r
822 <title>FILES</title>
\r
826 <emphasis>$GIT_DIR/COMMIT_EDITMSG</emphasis>
\r
830 This file contains the commit message of a commit in progress.
\r
831 If <emphasis>git commit</emphasis> exits due to an error before creating a commit,
\r
832 any commit message that has been provided by the user (e.g., in
\r
833 an editor session) will be available in this file, but will be
\r
834 overwritten by the next invocation of <emphasis>git commit</emphasis>.
\r
840 <simplesect id="git-commit(1)__see_also">
\r
841 <title>SEE ALSO</title>
\r
842 <simpara><xref linkend="git-add(1)" />,
\r
843 <xref linkend="git-rm(1)" />,
\r
844 <xref linkend="git-mv(1)" />,
\r
845 <xref linkend="git-merge(1)" />,
\r
846 <xref linkend="git-commit-tree(1)" /></simpara>
\r
848 <simplesect id="git-commit(1)__git">
\r
850 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
\r