1GIT-COMMIT(1) Git Manual GIT-COMMIT(1)
2
3
4
6 git-commit - Record changes to the repository
7
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
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
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
148 Add Signed-off-by line by the committer at the end of the commit
149 log message. The meaning of a signoff depends on the project, but
150 it typically certifies that committer has the rights to submit this
151 work under the same license and agrees to a Developer Certificate
152 of Origin (see http://developercertificate.org/ for more
153 information).
154
155 -n, --no-verify
156 This option bypasses the pre-commit and commit-msg hooks. See also
157 githooks(5).
158
159 --allow-empty
160 Usually recording a commit that has the exact same tree as its sole
161 parent commit is a mistake, and the command prevents you from
162 making such a commit. This option bypasses the safety, and is
163 primarily for use by foreign SCM interface scripts.
164
165 --allow-empty-message
166 Like --allow-empty this command is primarily for use by foreign SCM
167 interface scripts. It allows you to create a commit with an empty
168 commit message without using plumbing commands like git-commit-
169 tree(1).
170
171 --cleanup=<mode>
172 This option determines how the supplied commit message should be
173 cleaned up before committing. The <mode> can be strip, whitespace,
174 verbatim, scissors or default.
175
176 strip
177 Strip leading and trailing empty lines, trailing whitespace,
178 commentary and collapse consecutive empty lines.
179
180 whitespace
181 Same as strip except #commentary is not removed.
182
183 verbatim
184 Do not change the message at all.
185
186 scissors
187 Same as whitespace except that everything from (and including)
188 the line found below is truncated, if the message is to be
189 edited. "#" can be customized with core.commentChar.
190
191 # ------------------------ >8 ------------------------
192
193 default
194 Same as strip if the message is to be edited. Otherwise
195 whitespace.
196
197 The default can be changed by the commit.cleanup configuration
198 variable (see git-config(1)).
199
200 -e, --edit
201 The message taken from file with -F, command line with -m, and from
202 commit object with -C are usually used as the commit log message
203 unmodified. This option lets you further edit the message taken
204 from these sources.
205
206 --no-edit
207 Use the selected commit message without launching an editor. For
208 example, git commit --amend --no-edit amends a commit without
209 changing its commit message.
210
211 --amend
212 Replace the tip of the current branch by creating a new commit. The
213 recorded tree is prepared as usual (including the effect of the -i
214 and -o options and explicit pathspec), and the message from the
215 original commit is used as the starting point, instead of an empty
216 message, when no other message is specified from the command line
217 via options such as -m, -F, -c, etc. The new commit has the same
218 parents and author as the current one (the --reset-author option
219 can countermand this).
220
221 It is a rough equivalent for:
222
223 $ git reset --soft HEAD^
224 $ ... do something else to come up with the right tree ...
225 $ git commit -c ORIG_HEAD
226
227 but can be used to amend a merge commit.
228
229 You should understand the implications of rewriting history if you
230 amend a commit that has already been published. (See the
231 "RECOVERING FROM UPSTREAM REBASE" section in git-rebase(1).)
232
233 --no-post-rewrite
234 Bypass the post-rewrite hook.
235
236 -i, --include
237 Before making a commit out of staged contents so far, stage the
238 contents of paths given on the command line as well. This is
239 usually not what you want unless you are concluding a conflicted
240 merge.
241
242 -o, --only
243 Make a commit by taking the updated working tree contents of the
244 paths specified on the command line, disregarding any contents that
245 have been staged for other paths. This is the default mode of
246 operation of git commit if any paths are given on the command line,
247 in which case this option can be omitted. If this option is
248 specified together with --amend, then no paths need to be
249 specified, which can be used to amend the last commit without
250 committing changes that have already been staged. If used together
251 with --allow-empty paths are also not required, and an empty commit
252 will be created.
253
254 --pathspec-from-file=<file>
255 Pathspec is passed in <file> instead of commandline args. If <file>
256 is exactly - then standard input is used. Pathspec elements are
257 separated by LF or CR/LF. Pathspec elements can be quoted as
258 explained for the configuration variable core.quotePath (see git-
259 config(1)). See also --pathspec-file-nul and global
260 --literal-pathspecs.
261
262 --pathspec-file-nul
263 Only meaningful with --pathspec-from-file. Pathspec elements are
264 separated with NUL character and all other characters are taken
265 literally (including newlines and quotes).
266
267 -u[<mode>], --untracked-files[=<mode>]
268 Show untracked files.
269
270 The mode parameter is optional (defaults to all), and is used to
271 specify the handling of untracked files; when -u is not used, the
272 default is normal, i.e. show untracked files and directories.
273
274 The possible options are:
275
276 · no - Show no untracked files
277
278 · normal - Shows untracked files and directories
279
280 · all - Also shows individual files in untracked directories.
281
282 The default can be changed using the status.showUntrackedFiles
283 configuration variable documented in git-config(1).
284
285 -v, --verbose
286 Show unified diff between the HEAD commit and what would be
287 committed at the bottom of the commit message template to help the
288 user describe the commit by reminding what changes the commit has.
289 Note that this diff output doesn’t have its lines prefixed with #.
290 This diff will not be a part of the commit message. See the
291 commit.verbose configuration variable in git-config(1).
292
293 If specified twice, show in addition the unified diff between what
294 would be committed and the worktree files, i.e. the unstaged
295 changes to tracked files.
296
297 -q, --quiet
298 Suppress commit summary message.
299
300 --dry-run
301 Do not create a commit, but show a list of paths that are to be
302 committed, paths with local changes that will be left uncommitted
303 and paths that are untracked.
304
305 --status
306 Include the output of git-status(1) in the commit message template
307 when using an editor to prepare the commit message. Defaults to on,
308 but can be used to override configuration variable commit.status.
309
310 --no-status
311 Do not include the output of git-status(1) in the commit message
312 template when using an editor to prepare the default commit
313 message.
314
315 -S[<keyid>], --gpg-sign[=<keyid>]
316 GPG-sign commits. The keyid argument is optional and defaults to
317 the committer identity; if specified, it must be stuck to the
318 option without a space.
319
320 --no-gpg-sign
321 Countermand commit.gpgSign configuration variable that is set to
322 force each and every commit to be signed.
323
324 --
325 Do not interpret any more arguments as options.
326
327 <pathspec>...
328 When pathspec is given on the command line, commit the contents of
329 the files that match the pathspec without recording the changes
330 already added to the index. The contents of these files are also
331 staged for the next commit on top of what have been staged before.
332
333 For more details, see the pathspec entry in gitglossary(7).
334
336 When recording your own work, the contents of modified files in your
337 working tree are temporarily stored to a staging area called the
338 "index" with git add. A file can be reverted back, only in the index
339 but not in the working tree, to that of the last commit with git
340 restore --staged <file>, which effectively reverts git add and prevents
341 the changes to this file from participating in the next commit. After
342 building the state to be committed incrementally with these commands,
343 git commit (without any pathname parameter) is used to record what has
344 been staged so far. This is the most basic form of the command. An
345 example:
346
347 $ edit hello.c
348 $ git rm goodbye.c
349 $ git add hello.c
350 $ git commit
351
352 Instead of staging files after each individual change, you can tell git
353 commit to notice the changes to the files whose contents are tracked in
354 your working tree and do corresponding git add and git rm for you. That
355 is, this example does the same as the earlier example if there is no
356 other change in your working tree:
357
358 $ edit hello.c
359 $ rm goodbye.c
360 $ git commit -a
361
362 The command git commit -a first looks at your working tree, notices
363 that you have modified hello.c and removed goodbye.c, and performs
364 necessary git add and git rm for you.
365
366 After staging changes to many files, you can alter the order the
367 changes are recorded in, by giving pathnames to git commit. When
368 pathnames are given, the command makes a commit that only records the
369 changes made to the named paths:
370
371 $ edit hello.c hello.h
372 $ git add hello.c hello.h
373 $ edit Makefile
374 $ git commit Makefile
375
376 This makes a commit that records the modification to Makefile. The
377 changes staged for hello.c and hello.h are not included in the
378 resulting commit. However, their changes are not lost — they are still
379 staged and merely held back. After the above sequence, if you do:
380
381 $ git commit
382
383 this second commit would record the changes to hello.c and hello.h as
384 expected.
385
386 After a merge (initiated by git merge or git pull) stops because of
387 conflicts, cleanly merged paths are already staged to be committed for
388 you, and paths that conflicted are left in unmerged state. You would
389 have to first check which paths are conflicting with git status and
390 after fixing them manually in your working tree, you would stage the
391 result as usual with git add:
392
393 $ git status | grep unmerged
394 unmerged: hello.c
395 $ edit hello.c
396 $ git add hello.c
397
398 After resolving conflicts and staging the result, git ls-files -u would
399 stop mentioning the conflicted path. When you are done, run git commit
400 to finally record the merge:
401
402 $ git commit
403
404 As with the case to record your own changes, you can use -a option to
405 save typing. One difference is that during a merge resolution, you
406 cannot use git commit with pathnames to alter the order the changes are
407 committed, because the merge should be recorded as a single commit. In
408 fact, the command refuses to run when given pathnames (but see -i
409 option).
410
412 Author and committer information is taken from the following
413 environment variables, if set:
414
415 GIT_AUTHOR_NAME
416 GIT_AUTHOR_EMAIL
417 GIT_AUTHOR_DATE
418 GIT_COMMITTER_NAME
419 GIT_COMMITTER_EMAIL
420 GIT_COMMITTER_DATE
421
422 (nb "<", ">" and "\n"s are stripped)
423
424 The author and committer names are by convention some form of a
425 personal name (that is, the name by which other humans refer to you),
426 although Git does not enforce or require any particular form. Arbitrary
427 Unicode may be used, subject to the constraints listed above. This name
428 has no effect on authentication; for that, see the credential.username
429 variable in git-config(1).
430
431 In case (some of) these environment variables are not set, the
432 information is taken from the configuration items user.name and
433 user.email, or, if not present, the environment variable EMAIL, or, if
434 that is not set, system user name and the hostname used for outgoing
435 mail (taken from /etc/mailname and falling back to the fully qualified
436 hostname when that file does not exist).
437
438 The author.name and committer.name and their corresponding email
439 options override user.name and user.email if set and are overridden
440 themselves by the environment variables.
441
442 The typical usage is to set just the user.name and user.email
443 variables; the other options are provided for more complex use cases.
444
446 The GIT_AUTHOR_DATE, GIT_COMMITTER_DATE environment variables and the
447 --date option support the following date formats:
448
449 Git internal format
450 It is <unix timestamp> <time zone offset>, where <unix timestamp>
451 is the number of seconds since the UNIX epoch. <time zone offset>
452 is a positive or negative offset from UTC. For example CET (which
453 is 1 hour ahead of UTC) is +0100.
454
455 RFC 2822
456 The standard email format as described by RFC 2822, for example
457 Thu, 07 Apr 2005 22:13:13 +0200.
458
459 ISO 8601
460 Time and date specified by the ISO 8601 standard, for example
461 2005-04-07T22:13:13. The parser accepts a space instead of the T
462 character as well.
463
464 Note
465 In addition, the date part is accepted in the following
466 formats: YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY.
467
469 Though not required, it’s a good idea to begin the commit message with
470 a single short (less than 50 character) line summarizing the change,
471 followed by a blank line and then a more thorough description. The text
472 up to the first blank line in a commit message is treated as the commit
473 title, and that title is used throughout Git. For example, git-format-
474 patch(1) turns a commit into email, and it uses the title on the
475 Subject line and the rest of the commit in the body.
476
477 Git is to some extent character encoding agnostic.
478
479 · The contents of the blob objects are uninterpreted sequences of
480 bytes. There is no encoding translation at the core level.
481
482 · Path names are encoded in UTF-8 normalization form C. This applies
483 to tree objects, the index file, ref names, as well as path names
484 in command line arguments, environment variables and config files
485 (.git/config (see git-config(1)), gitignore(5), gitattributes(5)
486 and gitmodules(5)).
487
488 Note that Git at the core level treats path names simply as
489 sequences of non-NUL bytes, there are no path name encoding
490 conversions (except on Mac and Windows). Therefore, using non-ASCII
491 path names will mostly work even on platforms and file systems that
492 use legacy extended ASCII encodings. However, repositories created
493 on such systems will not work properly on UTF-8-based systems (e.g.
494 Linux, Mac, Windows) and vice versa. Additionally, many Git-based
495 tools simply assume path names to be UTF-8 and will fail to display
496 other encodings correctly.
497
498 · Commit log messages are typically encoded in UTF-8, but other
499 extended ASCII encodings are also supported. This includes
500 ISO-8859-x, CP125x and many others, but not UTF-16/32, EBCDIC and
501 CJK multi-byte encodings (GBK, Shift-JIS, Big5, EUC-x, CP9xx etc.).
502
503 Although we encourage that the commit log messages are encoded in
504 UTF-8, both the core and Git Porcelain are designed not to force UTF-8
505 on projects. If all participants of a particular project find it more
506 convenient to use legacy encodings, Git does not forbid it. However,
507 there are a few things to keep in mind.
508
509 1. git commit and git commit-tree issues a warning if the commit log
510 message given to it does not look like a valid UTF-8 string, unless
511 you explicitly say your project uses a legacy encoding. The way to
512 say this is to have i18n.commitencoding in .git/config file, like
513 this:
514
515 [i18n]
516 commitEncoding = ISO-8859-1
517
518 Commit objects created with the above setting record the value of
519 i18n.commitEncoding in its encoding header. This is to help other
520 people who look at them later. Lack of this header implies that the
521 commit log message is encoded in UTF-8.
522
523 2. git log, git show, git blame and friends look at the encoding
524 header of a commit object, and try to re-code the log message into
525 UTF-8 unless otherwise specified. You can specify the desired
526 output encoding with i18n.logOutputEncoding in .git/config file,
527 like this:
528
529 [i18n]
530 logOutputEncoding = ISO-8859-1
531
532 If you do not have this configuration variable, the value of
533 i18n.commitEncoding is used instead.
534
535 Note that we deliberately chose not to re-code the commit log message
536 when a commit is made to force UTF-8 at the commit object level,
537 because re-coding to UTF-8 is not necessarily a reversible operation.
538
540 The editor used to edit the commit log message will be chosen from the
541 GIT_EDITOR environment variable, the core.editor configuration
542 variable, the VISUAL environment variable, or the EDITOR environment
543 variable (in that order). See git-var(1) for details.
544
546 This command can run commit-msg, prepare-commit-msg, pre-commit,
547 post-commit and post-rewrite hooks. See githooks(5) for more
548 information.
549
551 $GIT_DIR/COMMIT_EDITMSG
552 This file contains the commit message of a commit in progress. If
553 git commit exits due to an error before creating a commit, any
554 commit message that has been provided by the user (e.g., in an
555 editor session) will be available in this file, but will be
556 overwritten by the next invocation of git commit.
557
559 git-add(1), git-rm(1), git-mv(1), git-merge(1), git-commit-tree(1)
560
562 Part of the git(1) suite
563
564
565
566Git 2.26.2 2020-04-20 GIT-COMMIT(1)