1GIT-COMMIT(1)                     Git Manual                     GIT-COMMIT(1)
2
3
4

NAME

6       git-commit - Record changes to the repository
7

SYNOPSIS

9       git commit [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend]
10                  [--dry-run] [(-c | -C | --fixup | --squash) <commit>]
11                  [-F <file> | -m <msg>] [--reset-author] [--allow-empty]
12                  [--allow-empty-message] [--no-verify] [-e] [--author=<author>]
13                  [--date=<date>] [--cleanup=<mode>] [--[no-]status]
14                  [-i | -o] [--pathspec-from-file=<file> [--pathspec-file-nul]]
15                  [-S[<keyid>]] [--] [<pathspec>...]
16

DESCRIPTION

18       Create a new commit containing the current contents of the index and
19       the given log message describing the changes. The new commit is a
20       direct child of HEAD, usually the tip of the current branch, and the
21       branch is updated to point to it (unless no branch is associated with
22       the working tree, in which case HEAD is "detached" as described in git-
23       checkout(1)).
24
25       The content to be committed can be specified in several ways:
26
27        1. by using git-add(1) to incrementally "add" changes to the index
28           before using the commit command (Note: even modified files must be
29           "added");
30
31        2. by using git-rm(1) to remove files from the working tree and the
32           index, again before using the commit command;
33
34        3. by listing files as arguments to the commit command (without
35           --interactive or --patch switch), in which case the commit will
36           ignore changes staged in the index, and instead record the current
37           content of the listed files (which must already be known to Git);
38
39        4. by using the -a switch with the commit command to automatically
40           "add" changes from all known files (i.e. all files that are already
41           listed in the index) and to automatically "rm" files in the index
42           that have been removed from the working tree, and then perform the
43           actual commit;
44
45        5. by using the --interactive or --patch switches with the commit
46           command to decide one by one which files or hunks should be part of
47           the commit in addition to contents in the index, before finalizing
48           the operation. See the “Interactive Mode” section of git-add(1) to
49           learn how to operate these modes.
50
51       The --dry-run option can be used to obtain a summary of what is
52       included by any of the above for the next commit by giving the same set
53       of parameters (options and paths).
54
55       If you make a commit and then find a mistake immediately after that,
56       you can recover from it with git reset.
57

OPTIONS

59       -a, --all
60           Tell the command to automatically stage files that have been
61           modified and deleted, but new files you have not told Git about are
62           not affected.
63
64       -p, --patch
65           Use the interactive patch selection interface to chose which
66           changes to commit. See git-add(1) for details.
67
68       -C <commit>, --reuse-message=<commit>
69           Take an existing commit object, and reuse the log message and the
70           authorship information (including the timestamp) when creating the
71           commit.
72
73       -c <commit>, --reedit-message=<commit>
74           Like -C, but with -c the editor is invoked, so that the user can
75           further edit the commit message.
76
77       --fixup=<commit>
78           Construct a commit message for use with rebase --autosquash. The
79           commit message will be the subject line from the specified commit
80           with a prefix of "fixup! ". See git-rebase(1) for details.
81
82       --squash=<commit>
83           Construct a commit message for use with rebase --autosquash. The
84           commit message subject line is taken from the specified commit with
85           a prefix of "squash! ". Can be used with additional commit message
86           options (-m/-c/-C/-F). See git-rebase(1) for details.
87
88       --reset-author
89           When used with -C/-c/--amend options, or when committing after a
90           conflicting cherry-pick, declare that the authorship of the
91           resulting commit now belongs to the committer. This also renews the
92           author timestamp.
93
94       --short
95           When doing a dry-run, give the output in the short-format. See git-
96           status(1) for details. Implies --dry-run.
97
98       --branch
99           Show the branch and tracking info even in short-format.
100
101       --porcelain
102           When doing a dry-run, give the output in a porcelain-ready format.
103           See git-status(1) for details. Implies --dry-run.
104
105       --long
106           When doing a dry-run, give the output in the long-format. Implies
107           --dry-run.
108
109       -z, --null
110           When showing short or porcelain status output, print the filename
111           verbatim and terminate the entries with NUL, instead of LF. If no
112           format is given, implies the --porcelain output format. Without the
113           -z option, filenames with "unusual" characters are quoted as
114           explained for the configuration variable core.quotePath (see git-
115           config(1)).
116
117       -F <file>, --file=<file>
118           Take the commit message from the given file. Use - to read the
119           message from the standard input.
120
121       --author=<author>
122           Override the commit author. Specify an explicit author using the
123           standard A U Thor <author@example.com> format. Otherwise <author>
124           is assumed to be a pattern and is used to search for an existing
125           commit by that author (i.e. rev-list --all -i --author=<author>);
126           the commit author is then copied from the first such commit found.
127
128       --date=<date>
129           Override the author date used in the commit.
130
131       -m <msg>, --message=<msg>
132           Use the given <msg> as the commit message. If multiple -m options
133           are given, their values are concatenated as separate paragraphs.
134
135           The -m option is mutually exclusive with -c, -C, and -F.
136
137       -t <file>, --template=<file>
138           When editing the commit message, start the editor with the contents
139           in the given file. The commit.template configuration variable is
140           often used to give this option implicitly to the command. This
141           mechanism can be used by projects that want to guide participants
142           with some hints on what to write in the message in what order. If
143           the user exits the editor without editing the message, the commit
144           is aborted. This has no effect when a message is given by other
145           means, e.g. with the -m or -F options.
146
147       -s, --signoff, --no-signoff
148           Add a Signed-off-by trailer by the committer at the end of the
149           commit log message. The meaning of a signoff depends on the project
150           to which you’re committing. For example, it may certify that the
151           committer has the rights to submit the work under the project’s
152           license or agrees to some contributor representation, such as a
153           Developer Certificate of Origin. (See
154           http://developercertificate.org for the one used by the Linux
155           kernel and Git projects.) Consult the documentation or leadership
156           of the project to which you’re contributing to understand how the
157           signoffs are used in that project.
158
159           The --no-signoff option can be used to countermand an earlier
160           --signoff option on the command line.
161
162       -n, --no-verify
163           This option bypasses the pre-commit and commit-msg hooks. See also
164           githooks(5).
165
166       --allow-empty
167           Usually recording a commit that has the exact same tree as its sole
168           parent commit is a mistake, and the command prevents you from
169           making such a commit. This option bypasses the safety, and is
170           primarily for use by foreign SCM interface scripts.
171
172       --allow-empty-message
173           Like --allow-empty this command is primarily for use by foreign SCM
174           interface scripts. It allows you to create a commit with an empty
175           commit message without using plumbing commands like git-commit-
176           tree(1).
177
178       --cleanup=<mode>
179           This option determines how the supplied commit message should be
180           cleaned up before committing. The <mode> can be strip, whitespace,
181           verbatim, scissors or default.
182
183           strip
184               Strip leading and trailing empty lines, trailing whitespace,
185               commentary and collapse consecutive empty lines.
186
187           whitespace
188               Same as strip except #commentary is not removed.
189
190           verbatim
191               Do not change the message at all.
192
193           scissors
194               Same as whitespace except that everything from (and including)
195               the line found below is truncated, if the message is to be
196               edited. "#" can be customized with core.commentChar.
197
198                   # ------------------------ >8 ------------------------
199
200           default
201               Same as strip if the message is to be edited. Otherwise
202               whitespace.
203
204           The default can be changed by the commit.cleanup configuration
205           variable (see git-config(1)).
206
207       -e, --edit
208           The message taken from file with -F, command line with -m, and from
209           commit object with -C are usually used as the commit log message
210           unmodified. This option lets you further edit the message taken
211           from these sources.
212
213       --no-edit
214           Use the selected commit message without launching an editor. For
215           example, git commit --amend --no-edit amends a commit without
216           changing its commit message.
217
218       --amend
219           Replace the tip of the current branch by creating a new commit. The
220           recorded tree is prepared as usual (including the effect of the -i
221           and -o options and explicit pathspec), and the message from the
222           original commit is used as the starting point, instead of an empty
223           message, when no other message is specified from the command line
224           via options such as -m, -F, -c, etc. The new commit has the same
225           parents and author as the current one (the --reset-author option
226           can countermand this).
227
228           It is a rough equivalent for:
229
230                       $ git reset --soft HEAD^
231                       $ ... do something else to come up with the right tree ...
232                       $ git commit -c ORIG_HEAD
233
234           but can be used to amend a merge commit.
235
236           You should understand the implications of rewriting history if you
237           amend a commit that has already been published. (See the
238           "RECOVERING FROM UPSTREAM REBASE" section in git-rebase(1).)
239
240       --no-post-rewrite
241           Bypass the post-rewrite hook.
242
243       -i, --include
244           Before making a commit out of staged contents so far, stage the
245           contents of paths given on the command line as well. This is
246           usually not what you want unless you are concluding a conflicted
247           merge.
248
249       -o, --only
250           Make a commit by taking the updated working tree contents of the
251           paths specified on the command line, disregarding any contents that
252           have been staged for other paths. This is the default mode of
253           operation of git commit if any paths are given on the command line,
254           in which case this option can be omitted. If this option is
255           specified together with --amend, then no paths need to be
256           specified, which can be used to amend the last commit without
257           committing changes that have already been staged. If used together
258           with --allow-empty paths are also not required, and an empty commit
259           will be created.
260
261       --pathspec-from-file=<file>
262           Pathspec is passed in <file> instead of commandline args. If <file>
263           is exactly - then standard input is used. Pathspec elements are
264           separated by LF or CR/LF. Pathspec elements can be quoted as
265           explained for the configuration variable core.quotePath (see git-
266           config(1)). See also --pathspec-file-nul and global
267           --literal-pathspecs.
268
269       --pathspec-file-nul
270           Only meaningful with --pathspec-from-file. Pathspec elements are
271           separated with NUL character and all other characters are taken
272           literally (including newlines and quotes).
273
274       -u[<mode>], --untracked-files[=<mode>]
275           Show untracked files.
276
277           The mode parameter is optional (defaults to all), and is used to
278           specify the handling of untracked files; when -u is not used, the
279           default is normal, i.e. show untracked files and directories.
280
281           The possible options are:
282
283no - Show no untracked files
284
285normal - Shows untracked files and directories
286
287all - Also shows individual files in untracked directories.
288
289           The default can be changed using the status.showUntrackedFiles
290           configuration variable documented in git-config(1).
291
292       -v, --verbose
293           Show unified diff between the HEAD commit and what would be
294           committed at the bottom of the commit message template to help the
295           user describe the commit by reminding what changes the commit has.
296           Note that this diff output doesn’t have its lines prefixed with #.
297           This diff will not be a part of the commit message. See the
298           commit.verbose configuration variable in git-config(1).
299
300           If specified twice, show in addition the unified diff between what
301           would be committed and the worktree files, i.e. the unstaged
302           changes to tracked files.
303
304       -q, --quiet
305           Suppress commit summary message.
306
307       --dry-run
308           Do not create a commit, but show a list of paths that are to be
309           committed, paths with local changes that will be left uncommitted
310           and paths that are untracked.
311
312       --status
313           Include the output of git-status(1) in the commit message template
314           when using an editor to prepare the commit message. Defaults to on,
315           but can be used to override configuration variable commit.status.
316
317       --no-status
318           Do not include the output of git-status(1) in the commit message
319           template when using an editor to prepare the default commit
320           message.
321
322       -S[<keyid>], --gpg-sign[=<keyid>], --no-gpg-sign
323           GPG-sign commits. The keyid argument is optional and defaults to
324           the committer identity; if specified, it must be stuck to the
325           option without a space.  --no-gpg-sign is useful to countermand
326           both commit.gpgSign configuration variable, and earlier --gpg-sign.
327
328       --
329           Do not interpret any more arguments as options.
330
331       <pathspec>...
332           When pathspec is given on the command line, commit the contents of
333           the files that match the pathspec without recording the changes
334           already added to the index. The contents of these files are also
335           staged for the next commit on top of what have been staged before.
336
337           For more details, see the pathspec entry in gitglossary(7).
338

EXAMPLES

340       When recording your own work, the contents of modified files in your
341       working tree are temporarily stored to a staging area called the
342       "index" with git add. A file can be reverted back, only in the index
343       but not in the working tree, to that of the last commit with git
344       restore --staged <file>, which effectively reverts git add and prevents
345       the changes to this file from participating in the next commit. After
346       building the state to be committed incrementally with these commands,
347       git commit (without any pathname parameter) is used to record what has
348       been staged so far. This is the most basic form of the command. An
349       example:
350
351           $ edit hello.c
352           $ git rm goodbye.c
353           $ git add hello.c
354           $ git commit
355
356       Instead of staging files after each individual change, you can tell git
357       commit to notice the changes to the files whose contents are tracked in
358       your working tree and do corresponding git add and git rm for you. That
359       is, this example does the same as the earlier example if there is no
360       other change in your working tree:
361
362           $ edit hello.c
363           $ rm goodbye.c
364           $ git commit -a
365
366       The command git commit -a first looks at your working tree, notices
367       that you have modified hello.c and removed goodbye.c, and performs
368       necessary git add and git rm for you.
369
370       After staging changes to many files, you can alter the order the
371       changes are recorded in, by giving pathnames to git commit. When
372       pathnames are given, the command makes a commit that only records the
373       changes made to the named paths:
374
375           $ edit hello.c hello.h
376           $ git add hello.c hello.h
377           $ edit Makefile
378           $ git commit Makefile
379
380       This makes a commit that records the modification to Makefile. The
381       changes staged for hello.c and hello.h are not included in the
382       resulting commit. However, their changes are not lost — they are still
383       staged and merely held back. After the above sequence, if you do:
384
385           $ git commit
386
387       this second commit would record the changes to hello.c and hello.h as
388       expected.
389
390       After a merge (initiated by git merge or git pull) stops because of
391       conflicts, cleanly merged paths are already staged to be committed for
392       you, and paths that conflicted are left in unmerged state. You would
393       have to first check which paths are conflicting with git status and
394       after fixing them manually in your working tree, you would stage the
395       result as usual with git add:
396
397           $ git status | grep unmerged
398           unmerged: hello.c
399           $ edit hello.c
400           $ git add hello.c
401
402       After resolving conflicts and staging the result, git ls-files -u would
403       stop mentioning the conflicted path. When you are done, run git commit
404       to finally record the merge:
405
406           $ git commit
407
408       As with the case to record your own changes, you can use -a option to
409       save typing. One difference is that during a merge resolution, you
410       cannot use git commit with pathnames to alter the order the changes are
411       committed, because the merge should be recorded as a single commit. In
412       fact, the command refuses to run when given pathnames (but see -i
413       option).
414

COMMIT INFORMATION

416       Author and committer information is taken from the following
417       environment variables, if set:
418
419           GIT_AUTHOR_NAME
420           GIT_AUTHOR_EMAIL
421           GIT_AUTHOR_DATE
422           GIT_COMMITTER_NAME
423           GIT_COMMITTER_EMAIL
424           GIT_COMMITTER_DATE
425
426       (nb "<", ">" and "\n"s are stripped)
427
428       The author and committer names are by convention some form of a
429       personal name (that is, the name by which other humans refer to you),
430       although Git does not enforce or require any particular form. Arbitrary
431       Unicode may be used, subject to the constraints listed above. This name
432       has no effect on authentication; for that, see the credential.username
433       variable in git-config(1).
434
435       In case (some of) these environment variables are not set, the
436       information is taken from the configuration items user.name and
437       user.email, or, if not present, the environment variable EMAIL, or, if
438       that is not set, system user name and the hostname used for outgoing
439       mail (taken from /etc/mailname and falling back to the fully qualified
440       hostname when that file does not exist).
441
442       The author.name and committer.name and their corresponding email
443       options override user.name and user.email if set and are overridden
444       themselves by the environment variables.
445
446       The typical usage is to set just the user.name and user.email
447       variables; the other options are provided for more complex use cases.
448

DATE FORMATS

450       The GIT_AUTHOR_DATE and GIT_COMMITTER_DATE environment variables
451       support the following date formats:
452
453       Git internal format
454           It is <unix timestamp> <time zone offset>, where <unix timestamp>
455           is the number of seconds since the UNIX epoch.  <time zone offset>
456           is a positive or negative offset from UTC. For example CET (which
457           is 1 hour ahead of UTC) is +0100.
458
459       RFC 2822
460           The standard email format as described by RFC 2822, for example
461           Thu, 07 Apr 2005 22:13:13 +0200.
462
463       ISO 8601
464           Time and date specified by the ISO 8601 standard, for example
465           2005-04-07T22:13:13. The parser accepts a space instead of the T
466           character as well. Fractional parts of a second will be ignored,
467           for example 2005-04-07T22:13:13.019 will be treated as
468           2005-04-07T22:13:13.
469
470               Note
471               In addition, the date part is accepted in the following
472               formats: YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY.
473
474       In addition to recognizing all date formats above, the --date option
475       will also try to make sense of other, more human-centric date formats,
476       such as relative dates like "yesterday" or "last Friday at noon".
477

DISCUSSION

479       Though not required, it’s a good idea to begin the commit message with
480       a single short (less than 50 character) line summarizing the change,
481       followed by a blank line and then a more thorough description. The text
482       up to the first blank line in a commit message is treated as the commit
483       title, and that title is used throughout Git. For example, git-format-
484       patch(1) turns a commit into email, and it uses the title on the
485       Subject line and the rest of the commit in the body.
486
487       Git is to some extent character encoding agnostic.
488
489       •   The contents of the blob objects are uninterpreted sequences of
490           bytes. There is no encoding translation at the core level.
491
492       •   Path names are encoded in UTF-8 normalization form C. This applies
493           to tree objects, the index file, ref names, as well as path names
494           in command line arguments, environment variables and config files
495           (.git/config (see git-config(1)), gitignore(5), gitattributes(5)
496           and gitmodules(5)).
497
498           Note that Git at the core level treats path names simply as
499           sequences of non-NUL bytes, there are no path name encoding
500           conversions (except on Mac and Windows). Therefore, using non-ASCII
501           path names will mostly work even on platforms and file systems that
502           use legacy extended ASCII encodings. However, repositories created
503           on such systems will not work properly on UTF-8-based systems (e.g.
504           Linux, Mac, Windows) and vice versa. Additionally, many Git-based
505           tools simply assume path names to be UTF-8 and will fail to display
506           other encodings correctly.
507
508       •   Commit log messages are typically encoded in UTF-8, but other
509           extended ASCII encodings are also supported. This includes
510           ISO-8859-x, CP125x and many others, but not UTF-16/32, EBCDIC and
511           CJK multi-byte encodings (GBK, Shift-JIS, Big5, EUC-x, CP9xx etc.).
512
513       Although we encourage that the commit log messages are encoded in
514       UTF-8, both the core and Git Porcelain are designed not to force UTF-8
515       on projects. If all participants of a particular project find it more
516       convenient to use legacy encodings, Git does not forbid it. However,
517       there are a few things to keep in mind.
518
519        1. git commit and git commit-tree issues a warning if the commit log
520           message given to it does not look like a valid UTF-8 string, unless
521           you explicitly say your project uses a legacy encoding. The way to
522           say this is to have i18n.commitEncoding in .git/config file, like
523           this:
524
525               [i18n]
526                       commitEncoding = ISO-8859-1
527
528           Commit objects created with the above setting record the value of
529           i18n.commitEncoding in its encoding header. This is to help other
530           people who look at them later. Lack of this header implies that the
531           commit log message is encoded in UTF-8.
532
533        2. git log, git show, git blame and friends look at the encoding
534           header of a commit object, and try to re-code the log message into
535           UTF-8 unless otherwise specified. You can specify the desired
536           output encoding with i18n.logOutputEncoding in .git/config file,
537           like this:
538
539               [i18n]
540                       logOutputEncoding = ISO-8859-1
541
542           If you do not have this configuration variable, the value of
543           i18n.commitEncoding is used instead.
544
545       Note that we deliberately chose not to re-code the commit log message
546       when a commit is made to force UTF-8 at the commit object level,
547       because re-coding to UTF-8 is not necessarily a reversible operation.
548

ENVIRONMENT AND CONFIGURATION VARIABLES

550       The editor used to edit the commit log message will be chosen from the
551       GIT_EDITOR environment variable, the core.editor configuration
552       variable, the VISUAL environment variable, or the EDITOR environment
553       variable (in that order). See git-var(1) for details.
554

HOOKS

556       This command can run commit-msg, prepare-commit-msg, pre-commit,
557       post-commit and post-rewrite hooks. See githooks(5) for more
558       information.
559

FILES

561       $GIT_DIR/COMMIT_EDITMSG
562           This file contains the commit message of a commit in progress. If
563           git commit exits due to an error before creating a commit, any
564           commit message that has been provided by the user (e.g., in an
565           editor session) will be available in this file, but will be
566           overwritten by the next invocation of git commit.
567

SEE ALSO

569       git-add(1), git-rm(1), git-mv(1), git-merge(1), git-commit-tree(1)
570

GIT

572       Part of the git(1) suite
573
574
575
576Git 2.31.1                        2021-03-26                     GIT-COMMIT(1)
Impressum