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] [-S[<keyid>]] [--] [<file>...]
15
16

DESCRIPTION

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

OPTIONS

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

DATE FORMATS

317       The GIT_AUTHOR_DATE, GIT_COMMITTER_DATE environment variables and the
318       --date option support the following date formats:
319
320       Git internal format
321           It is <unix timestamp> <time zone offset>, where <unix timestamp>
322           is the number of seconds since the UNIX epoch.  <time zone offset>
323           is a positive or negative offset from UTC. For example CET (which
324           is 1 hour ahead of UTC) is +0100.
325
326       RFC 2822
327           The standard email format as described by RFC 2822, for example
328           Thu, 07 Apr 2005 22:13:13 +0200.
329
330       ISO 8601
331           Time and date specified by the ISO 8601 standard, for example
332           2005-04-07T22:13:13. The parser accepts a space instead of the T
333           character as well.
334
335               Note
336               In addition, the date part is accepted in the following
337               formats: YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY.
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 reset
344       HEAD -- <file>, which effectively reverts git add and prevents the
345       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
357       Instead of staging files after each individual change, you can tell git
358       commit to notice the changes to the files whose contents are tracked in
359       your working tree and do corresponding git add and git rm for you. That
360       is, this example does the same as the earlier example if there is no
361       other change in your working tree:
362
363           $ edit hello.c
364           $ rm goodbye.c
365           $ git commit -a
366
367
368       The command git commit -a first looks at your working tree, notices
369       that you have modified hello.c and removed goodbye.c, and performs
370       necessary git add and git rm for you.
371
372       After staging changes to many files, you can alter the order the
373       changes are recorded in, by giving pathnames to git commit. When
374       pathnames are given, the command makes a commit that only records the
375       changes made to the named paths:
376
377           $ edit hello.c hello.h
378           $ git add hello.c hello.h
379           $ edit Makefile
380           $ git commit Makefile
381
382
383       This makes a commit that records the modification to Makefile. The
384       changes staged for hello.c and hello.h are not included in the
385       resulting commit. However, their changes are not lost — they are still
386       staged and merely held back. After the above sequence, if you do:
387
388           $ git commit
389
390
391       this second commit would record the changes to hello.c and hello.h as
392       expected.
393
394       After a merge (initiated by git merge or git pull) stops because of
395       conflicts, cleanly merged paths are already staged to be committed for
396       you, and paths that conflicted are left in unmerged state. You would
397       have to first check which paths are conflicting with git status and
398       after fixing them manually in your working tree, you would stage the
399       result as usual with git add:
400
401           $ git status | grep unmerged
402           unmerged: hello.c
403           $ edit hello.c
404           $ git add hello.c
405
406
407       After resolving conflicts and staging the result, git ls-files -u would
408       stop mentioning the conflicted path. When you are done, run git commit
409       to finally record the merge:
410
411           $ git commit
412
413
414       As with the case to record your own changes, you can use -a option to
415       save typing. One difference is that during a merge resolution, you
416       cannot use git commit with pathnames to alter the order the changes are
417       committed, because the merge should be recorded as a single commit. In
418       fact, the command refuses to run when given pathnames (but see -i
419       option).
420

DISCUSSION

422       Though not required, it’s a good idea to begin the commit message with
423       a single short (less than 50 character) line summarizing the change,
424       followed by a blank line and then a more thorough description. The text
425       up to the first blank line in a commit message is treated as the commit
426       title, and that title is used throughout Git. For example, git-format-
427       patch(1) turns a commit into email, and it uses the title on the
428       Subject line and the rest of the commit in the body.
429
430       Git is to some extent character encoding agnostic.
431
432       ·   The contents of the blob objects are uninterpreted sequences of
433           bytes. There is no encoding translation at the core level.
434
435       ·   Path names are encoded in UTF-8 normalization form C. This applies
436           to tree objects, the index file, ref names, as well as path names
437           in command line arguments, environment variables and config files
438           (.git/config (see git-config(1)), gitignore(5), gitattributes(5)
439           and gitmodules(5)).
440
441           Note that Git at the core level treats path names simply as
442           sequences of non-NUL bytes, there are no path name encoding
443           conversions (except on Mac and Windows). Therefore, using non-ASCII
444           path names will mostly work even on platforms and file systems that
445           use legacy extended ASCII encodings. However, repositories created
446           on such systems will not work properly on UTF-8-based systems (e.g.
447           Linux, Mac, Windows) and vice versa. Additionally, many Git-based
448           tools simply assume path names to be UTF-8 and will fail to display
449           other encodings correctly.
450
451       ·   Commit log messages are typically encoded in UTF-8, but other
452           extended ASCII encodings are also supported. This includes
453           ISO-8859-x, CP125x and many others, but not UTF-16/32, EBCDIC and
454           CJK multi-byte encodings (GBK, Shift-JIS, Big5, EUC-x, CP9xx etc.).
455
456       Although we encourage that the commit log messages are encoded in
457       UTF-8, both the core and Git Porcelain are designed not to force UTF-8
458       on projects. If all participants of a particular project find it more
459       convenient to use legacy encodings, Git does not forbid it. However,
460       there are a few things to keep in mind.
461
462        1. git commit and git commit-tree issues a warning if the commit log
463           message given to it does not look like a valid UTF-8 string, unless
464           you explicitly say your project uses a legacy encoding. The way to
465           say this is to have i18n.commitencoding in .git/config file, like
466           this:
467
468               [i18n]
469                       commitEncoding = ISO-8859-1
470
471           Commit objects created with the above setting record the value of
472           i18n.commitEncoding in its encoding header. This is to help other
473           people who look at them later. Lack of this header implies that the
474           commit log message is encoded in UTF-8.
475
476        2. git log, git show, git blame and friends look at the encoding
477           header of a commit object, and try to re-code the log message into
478           UTF-8 unless otherwise specified. You can specify the desired
479           output encoding with i18n.logOutputEncoding in .git/config file,
480           like this:
481
482               [i18n]
483                       logOutputEncoding = ISO-8859-1
484
485           If you do not have this configuration variable, the value of
486           i18n.commitEncoding is used instead.
487
488       Note that we deliberately chose not to re-code the commit log message
489       when a commit is made to force UTF-8 at the commit object level,
490       because re-coding to UTF-8 is not necessarily a reversible operation.
491

ENVIRONMENT AND CONFIGURATION VARIABLES

493       The editor used to edit the commit log message will be chosen from the
494       GIT_EDITOR environment variable, the core.editor configuration
495       variable, the VISUAL environment variable, or the EDITOR environment
496       variable (in that order). See git-var(1) for details.
497

HOOKS

499       This command can run commit-msg, prepare-commit-msg, pre-commit,
500       post-commit and post-rewrite hooks. See githooks(5) for more
501       information.
502

FILES

504       $GIT_DIR/COMMIT_EDITMSG
505           This file contains the commit message of a commit in progress. If
506           git commit exits due to an error before creating a commit, any
507           commit message that has been provided by the user (e.g., in an
508           editor session) will be available in this file, but will be
509           overwritten by the next invocation of git commit.
510

SEE ALSO

512       git-add(1), git-rm(1), git-mv(1), git-merge(1), git-commit-tree(1)
513

GIT

515       Part of the git(1) suite
516
517
518
519Git 2.18.1                        05/14/2019                     GIT-COMMIT(1)
Impressum