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] [-S[<keyid>]] [--] [<file>...]
15
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 -u[<mode>], --untracked-files[=<mode>]
255 Show untracked files.
256
257 The mode parameter is optional (defaults to all), and is used to
258 specify the handling of untracked files; when -u is not used, the
259 default is normal, i.e. show untracked files and directories.
260
261 The possible options are:
262
263 · no - Show no untracked files
264
265 · normal - Shows untracked files and directories
266
267 · all - Also shows individual files in untracked directories.
268
269 The default can be changed using the status.showUntrackedFiles
270 configuration variable documented in git-config(1).
271
272 -v, --verbose
273 Show unified diff between the HEAD commit and what would be
274 committed at the bottom of the commit message template to help the
275 user describe the commit by reminding what changes the commit has.
276 Note that this diff output doesn’t have its lines prefixed with #.
277 This diff will not be a part of the commit message. See the
278 commit.verbose configuration variable in git-config(1).
279
280 If specified twice, show in addition the unified diff between what
281 would be committed and the worktree files, i.e. the unstaged
282 changes to tracked files.
283
284 -q, --quiet
285 Suppress commit summary message.
286
287 --dry-run
288 Do not create a commit, but show a list of paths that are to be
289 committed, paths with local changes that will be left uncommitted
290 and paths that are untracked.
291
292 --status
293 Include the output of git-status(1) in the commit message template
294 when using an editor to prepare the commit message. Defaults to on,
295 but can be used to override configuration variable commit.status.
296
297 --no-status
298 Do not include the output of git-status(1) in the commit message
299 template when using an editor to prepare the default commit
300 message.
301
302 -S[<keyid>], --gpg-sign[=<keyid>]
303 GPG-sign commits. The keyid argument is optional and defaults to
304 the committer identity; if specified, it must be stuck to the
305 option without a space.
306
307 --no-gpg-sign
308 Countermand commit.gpgSign configuration variable that is set to
309 force each and every commit to be signed.
310
311 --
312 Do not interpret any more arguments as options.
313
314 <file>...
315 When files are given on the command line, the command commits the
316 contents of the named files, without recording the changes already
317 staged. The contents of these files are also staged for the next
318 commit on top of what have been staged before.
319
321 The GIT_AUTHOR_DATE, GIT_COMMITTER_DATE environment variables and the
322 --date option support the following date formats:
323
324 Git internal format
325 It is <unix timestamp> <time zone offset>, where <unix timestamp>
326 is the number of seconds since the UNIX epoch. <time zone offset>
327 is a positive or negative offset from UTC. For example CET (which
328 is 1 hour ahead of UTC) is +0100.
329
330 RFC 2822
331 The standard email format as described by RFC 2822, for example
332 Thu, 07 Apr 2005 22:13:13 +0200.
333
334 ISO 8601
335 Time and date specified by the ISO 8601 standard, for example
336 2005-04-07T22:13:13. The parser accepts a space instead of the T
337 character as well.
338
339 Note
340 In addition, the date part is accepted in the following
341 formats: YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY.
342
344 When recording your own work, the contents of modified files in your
345 working tree are temporarily stored to a staging area called the
346 "index" with git add. A file can be reverted back, only in the index
347 but not in the working tree, to that of the last commit with git
348 restore --staged <file>, which effectively reverts git add and prevents
349 the changes to this file from participating in the next commit. After
350 building the state to be committed incrementally with these commands,
351 git commit (without any pathname parameter) is used to record what has
352 been staged so far. This is the most basic form of the command. An
353 example:
354
355 $ edit hello.c
356 $ git rm goodbye.c
357 $ git add hello.c
358 $ git commit
359
360
361 Instead of staging files after each individual change, you can tell git
362 commit to notice the changes to the files whose contents are tracked in
363 your working tree and do corresponding git add and git rm for you. That
364 is, this example does the same as the earlier example if there is no
365 other change in your working tree:
366
367 $ edit hello.c
368 $ rm goodbye.c
369 $ git commit -a
370
371
372 The command git commit -a first looks at your working tree, notices
373 that you have modified hello.c and removed goodbye.c, and performs
374 necessary git add and git rm for you.
375
376 After staging changes to many files, you can alter the order the
377 changes are recorded in, by giving pathnames to git commit. When
378 pathnames are given, the command makes a commit that only records the
379 changes made to the named paths:
380
381 $ edit hello.c hello.h
382 $ git add hello.c hello.h
383 $ edit Makefile
384 $ git commit Makefile
385
386
387 This makes a commit that records the modification to Makefile. The
388 changes staged for hello.c and hello.h are not included in the
389 resulting commit. However, their changes are not lost — they are still
390 staged and merely held back. After the above sequence, if you do:
391
392 $ git commit
393
394
395 this second commit would record the changes to hello.c and hello.h as
396 expected.
397
398 After a merge (initiated by git merge or git pull) stops because of
399 conflicts, cleanly merged paths are already staged to be committed for
400 you, and paths that conflicted are left in unmerged state. You would
401 have to first check which paths are conflicting with git status and
402 after fixing them manually in your working tree, you would stage the
403 result as usual with git add:
404
405 $ git status | grep unmerged
406 unmerged: hello.c
407 $ edit hello.c
408 $ git add hello.c
409
410
411 After resolving conflicts and staging the result, git ls-files -u would
412 stop mentioning the conflicted path. When you are done, run git commit
413 to finally record the merge:
414
415 $ git commit
416
417
418 As with the case to record your own changes, you can use -a option to
419 save typing. One difference is that during a merge resolution, you
420 cannot use git commit with pathnames to alter the order the changes are
421 committed, because the merge should be recorded as a single commit. In
422 fact, the command refuses to run when given pathnames (but see -i
423 option).
424
426 Though not required, it’s a good idea to begin the commit message with
427 a single short (less than 50 character) line summarizing the change,
428 followed by a blank line and then a more thorough description. The text
429 up to the first blank line in a commit message is treated as the commit
430 title, and that title is used throughout Git. For example, git-format-
431 patch(1) turns a commit into email, and it uses the title on the
432 Subject line and the rest of the commit in the body.
433
434 Git is to some extent character encoding agnostic.
435
436 · The contents of the blob objects are uninterpreted sequences of
437 bytes. There is no encoding translation at the core level.
438
439 · Path names are encoded in UTF-8 normalization form C. This applies
440 to tree objects, the index file, ref names, as well as path names
441 in command line arguments, environment variables and config files
442 (.git/config (see git-config(1)), gitignore(5), gitattributes(5)
443 and gitmodules(5)).
444
445 Note that Git at the core level treats path names simply as
446 sequences of non-NUL bytes, there are no path name encoding
447 conversions (except on Mac and Windows). Therefore, using non-ASCII
448 path names will mostly work even on platforms and file systems that
449 use legacy extended ASCII encodings. However, repositories created
450 on such systems will not work properly on UTF-8-based systems (e.g.
451 Linux, Mac, Windows) and vice versa. Additionally, many Git-based
452 tools simply assume path names to be UTF-8 and will fail to display
453 other encodings correctly.
454
455 · Commit log messages are typically encoded in UTF-8, but other
456 extended ASCII encodings are also supported. This includes
457 ISO-8859-x, CP125x and many others, but not UTF-16/32, EBCDIC and
458 CJK multi-byte encodings (GBK, Shift-JIS, Big5, EUC-x, CP9xx etc.).
459
460 Although we encourage that the commit log messages are encoded in
461 UTF-8, both the core and Git Porcelain are designed not to force UTF-8
462 on projects. If all participants of a particular project find it more
463 convenient to use legacy encodings, Git does not forbid it. However,
464 there are a few things to keep in mind.
465
466 1. git commit and git commit-tree issues a warning if the commit log
467 message given to it does not look like a valid UTF-8 string, unless
468 you explicitly say your project uses a legacy encoding. The way to
469 say this is to have i18n.commitencoding in .git/config file, like
470 this:
471
472 [i18n]
473 commitEncoding = ISO-8859-1
474
475 Commit objects created with the above setting record the value of
476 i18n.commitEncoding in its encoding header. This is to help other
477 people who look at them later. Lack of this header implies that the
478 commit log message is encoded in UTF-8.
479
480 2. git log, git show, git blame and friends look at the encoding
481 header of a commit object, and try to re-code the log message into
482 UTF-8 unless otherwise specified. You can specify the desired
483 output encoding with i18n.logOutputEncoding in .git/config file,
484 like this:
485
486 [i18n]
487 logOutputEncoding = ISO-8859-1
488
489 If you do not have this configuration variable, the value of
490 i18n.commitEncoding is used instead.
491
492 Note that we deliberately chose not to re-code the commit log message
493 when a commit is made to force UTF-8 at the commit object level,
494 because re-coding to UTF-8 is not necessarily a reversible operation.
495
497 The editor used to edit the commit log message will be chosen from the
498 GIT_EDITOR environment variable, the core.editor configuration
499 variable, the VISUAL environment variable, or the EDITOR environment
500 variable (in that order). See git-var(1) for details.
501
503 This command can run commit-msg, prepare-commit-msg, pre-commit,
504 post-commit and post-rewrite hooks. See githooks(5) for more
505 information.
506
508 $GIT_DIR/COMMIT_EDITMSG
509 This file contains the commit message of a commit in progress. If
510 git commit exits due to an error before creating a commit, any
511 commit message that has been provided by the user (e.g., in an
512 editor session) will be available in this file, but will be
513 overwritten by the next invocation of git commit.
514
516 git-add(1), git-rm(1), git-mv(1), git-merge(1), git-commit-tree(1)
517
519 Part of the git(1) suite
520
521
522
523Git 2.24.1 12/10/2019 GIT-COMMIT(1)