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, in which case
31           the commit will ignore changes staged in the index, and instead
32           record the current content of the listed files (which must already
33           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, before finalizing the operation. See the “Interactive
44           Mode” section of git-add(1) to learn how to operate these modes.
45
46       The --dry-run option can be used to obtain a summary of what is
47       included by any of the above for the next commit by giving the same set
48       of parameters (options and paths).
49
50       If you make a commit and then find a mistake immediately after that,
51       you can recover from it with git reset.
52

OPTIONS

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

DATE FORMATS

284       The GIT_AUTHOR_DATE, GIT_COMMITTER_DATE environment variables and the
285       --date option support the following date formats:
286
287       Git internal format
288           It is <unix timestamp> <timezone offset>, where <unix timestamp> is
289           the number of seconds since the UNIX epoch.  <timezone offset> is a
290           positive or negative offset from UTC. For example CET (which is 2
291           hours ahead UTC) is +0200.
292
293       RFC 2822
294           The standard email format as described by RFC 2822, for example
295           Thu, 07 Apr 2005 22:13:13 +0200.
296
297       ISO 8601
298           Time and date specified by the ISO 8601 standard, for example
299           2005-04-07T22:13:13. The parser accepts a space instead of the T
300           character as well.
301
302               Note
303               In addition, the date part is accepted in the following
304               formats: YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY.
305

EXAMPLES

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

DISCUSSION

389       Though not required, it’s a good idea to begin the commit message with
390       a single short (less than 50 character) line summarizing the change,
391       followed by a blank line and then a more thorough description. The text
392       up to the first blank line in a commit message is treated as the commit
393       title, and that title is used throughout Git. For example, git-format-
394       patch(1) turns a commit into email, and it uses the title on the
395       Subject line and the rest of the commit in the body.
396
397       At the core level, Git is character encoding agnostic.
398
399       ·   The pathnames recorded in the index and in the tree objects are
400           treated as uninterpreted sequences of non-NUL bytes. What
401           readdir(2) returns are what are recorded and compared with the data
402           Git keeps track of, which in turn are expected to be what lstat(2)
403           and creat(2) accepts. There is no such thing as pathname encoding
404           translation.
405
406       ·   The contents of the blob objects are uninterpreted sequences of
407           bytes. There is no encoding translation at the core level.
408
409       ·   The commit log messages are uninterpreted sequences of non-NUL
410           bytes.
411
412       Although we encourage that the commit log messages are encoded in
413       UTF-8, both the core and Git Porcelain are designed not to force UTF-8
414       on projects. If all participants of a particular project find it more
415       convenient to use legacy encodings, Git does not forbid it. However,
416       there are a few things to keep in mind.
417
418        1. git commit and git commit-tree issues a warning if the commit log
419           message given to it does not look like a valid UTF-8 string, unless
420           you explicitly say your project uses a legacy encoding. The way to
421           say this is to have i18n.commitencoding in .git/config file, like
422           this:
423
424               [i18n]
425                       commitencoding = ISO-8859-1
426
427           Commit objects created with the above setting record the value of
428           i18n.commitencoding in its encoding header. This is to help other
429           people who look at them later. Lack of this header implies that the
430           commit log message is encoded in UTF-8.
431
432        2. git log, git show, git blame and friends look at the encoding
433           header of a commit object, and try to re-code the log message into
434           UTF-8 unless otherwise specified. You can specify the desired
435           output encoding with i18n.logoutputencoding in .git/config file,
436           like this:
437
438               [i18n]
439                       logoutputencoding = ISO-8859-1
440
441           If you do not have this configuration variable, the value of
442           i18n.commitencoding is used instead.
443
444       Note that we deliberately chose not to re-code the commit log message
445       when a commit is made to force UTF-8 at the commit object level,
446       because re-coding to UTF-8 is not necessarily a reversible operation.
447

ENVIRONMENT AND CONFIGURATION VARIABLES

449       The editor used to edit the commit log message will be chosen from the
450       GIT_EDITOR environment variable, the core.editor configuration
451       variable, the VISUAL environment variable, or the EDITOR environment
452       variable (in that order). See git-var(1) for details.
453

HOOKS

455       This command can run commit-msg, prepare-commit-msg, pre-commit, and
456       post-commit hooks. See githooks(5) for more information.
457

FILES

459       $GIT_DIR/COMMIT_EDITMSG
460           This file contains the commit message of a commit in progress. If
461           git commit exits due to an error before creating a commit, any
462           commit message that has been provided by the user (e.g., in an
463           editor session) will be available in this file, but will be
464           overwritten by the next invocation of git commit.
465

SEE ALSO

467       git-add(1), git-rm(1), git-mv(1), git-merge(1), git-commit-tree(1)
468

GIT

470       Part of the git(1) suite
471
472
473
474Git 1.8.3.1                       11/19/2018                     GIT-COMMIT(1)
Impressum