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] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
10                  [(-c | -C | --fixup | --squash) <commit>] [-F <file> | -m <msg>]
11                  [--reset-author] [--allow-empty] [--allow-empty-message] [--no-verify]
12                  [-e] [--author=<author>] [--date=<date>] [--cleanup=<mode>]
13                  [--status | --no-status] [-i | -o] [--] [<file>...]
14
15

DESCRIPTION

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

OPTIONS

53       -a, --all
54           Tell the command to automatically stage files that have been
55           modified and deleted, but new files you have not told git about are
56           not affected.
57
58       -C <commit>, --reuse-message=<commit>
59           Take an existing commit object, and reuse the log message and the
60           authorship information (including the timestamp) when creating the
61           commit.
62
63       -c <commit>, --reedit-message=<commit>
64           Like -C, but with -c the editor is invoked, so that the user can
65           further edit the commit message.
66
67       --fixup=<commit>
68           Construct a commit message for use with rebase --autosquash. The
69           commit message will be the subject line from the specified commit
70           with a prefix of "fixup! ". See git-rebase(1) for details.
71
72       --squash=<commit>
73           Construct a commit message for use with rebase --autosquash. The
74           commit message subject line is taken from the specified commit with
75           a prefix of "squash! ". Can be used with additional commit message
76           options (-m/-c/-C/-F). See git-rebase(1) for details.
77
78       --reset-author
79           When used with -C/-c/--amend options, declare that the authorship
80           of the resulting commit now belongs of the committer. This also
81           renews the author timestamp.
82
83       --short
84           When doing a dry-run, give the output in the short-format. See git-
85           status(1) for details. Implies --dry-run.
86
87       --porcelain
88           When doing a dry-run, give the output in a porcelain-ready format.
89           See git-status(1) for details. Implies --dry-run.
90
91       -z
92           When showing short or porcelain status output, terminate entries in
93           the status output with NUL, instead of LF. If no format is given,
94           implies the --porcelain output format.
95
96       -F <file>, --file=<file>
97           Take the commit message from the given file. Use - to read the
98           message from the standard input.
99
100       --author=<author>
101           Override the commit author. Specify an explicit author using the
102           standard A U Thor <author@example.com[1]> format. Otherwise
103           <author> is assumed to be a pattern and is used to search for an
104           existing commit by that author (i.e. rev-list --all -i
105           --author=<author>); the commit author is then copied from the first
106           such commit found.
107
108       --date=<date>
109           Override the author date used in the commit.
110
111       -m <msg>, --message=<msg>
112           Use the given <msg> as the commit message.
113
114       -t <file>, --template=<file>
115           Use the contents of the given file as the initial version of the
116           commit message. The editor is invoked and you can make subsequent
117           changes. If a message is specified using the -m or -F options, this
118           option has no effect. This overrides the commit.template
119           configuration variable.
120
121       -s, --signoff
122           Add Signed-off-by line by the committer at the end of the commit
123           log message.
124
125       -n, --no-verify
126           This option bypasses the pre-commit and commit-msg hooks. See also
127           githooks(5).
128
129       --allow-empty
130           Usually recording a commit that has the exact same tree as its sole
131           parent commit is a mistake, and the command prevents you from
132           making such a commit. This option bypasses the safety, and is
133           primarily for use by foreign SCM interface scripts.
134
135       --allow-empty-message
136           Like --allow-empty this command is primarily for use by foreign SCM
137           interface scripts. It allows you to create a commit with an empty
138           commit message without using plumbing commands like git-commit-
139           tree(1).
140
141       --cleanup=<mode>
142           This option sets how the commit message is cleaned up. The <mode>
143           can be one of verbatim, whitespace, strip, and default. The default
144           mode will strip leading and trailing empty lines and #commentary
145           from the commit message only if the message is to be edited.
146           Otherwise only whitespace removed. The verbatim mode does not
147           change message at all, whitespace removes just leading/trailing
148           whitespace lines and strip removes both whitespace and commentary.
149
150       -e, --edit
151           The message taken from file with -F, command line with -m, and from
152           file with -C are usually used as the commit log message unmodified.
153           This option lets you further edit the message taken from these
154           sources.
155
156       --amend
157           Used to amend the tip of the current branch. Prepare the tree
158           object you would want to replace the latest commit as usual (this
159           includes the usual -i/-o and explicit paths), and the commit log
160           editor is seeded with the commit message from the tip of the
161           current branch. The commit you create replaces the current tip — if
162           it was a merge, it will have the parents of the current tip as
163           parents — so the current top commit is discarded.
164
165           It is a rough equivalent for:
166
167                       $ git reset --soft HEAD^
168                       $ ... do something else to come up with the right tree ...
169                       $ git commit -c ORIG_HEAD
170
171           but can be used to amend a merge commit.
172
173           You should understand the implications of rewriting history if you
174           amend a commit that has already been published. (See the
175           "RECOVERING FROM UPSTREAM REBASE" section in git-rebase(1).)
176
177       -i, --include
178           Before making a commit out of staged contents so far, stage the
179           contents of paths given on the command line as well. This is
180           usually not what you want unless you are concluding a conflicted
181           merge.
182
183       -o, --only
184           Make a commit only from the paths specified on the command line,
185           disregarding any contents that have been staged so far. This is the
186           default mode of operation of git commit if any paths are given on
187           the command line, in which case this option can be omitted. If this
188           option is specified together with --amend, then no paths need to be
189           specified, which can be used to amend the last commit without
190           committing changes that have already been staged.
191
192       -u[<mode>], --untracked-files[=<mode>]
193           Show untracked files.
194
195           The mode parameter is optional (defaults to all), and is used to
196           specify the handling of untracked files; when -u is not used, the
197           default is normal, i.e. show untracked files and directories.
198
199           The possible options are:
200
201           ·    no - Show no untracked files
202
203           ·    normal - Shows untracked files and directories
204
205           ·    all - Also shows individual files in untracked directories.
206
207               The default can be changed using the status.showUntrackedFiles
208               configuration variable documented in git-config(1).
209
210       -v, --verbose
211           Show unified diff between the HEAD commit and what would be
212           committed at the bottom of the commit message template. Note that
213           this diff output doesn’t have its lines prefixed with #.
214
215       -q, --quiet
216           Suppress commit summary message.
217
218       --dry-run
219           Do not create a commit, but show a list of paths that are to be
220           committed, paths with local changes that will be left uncommitted
221           and paths that are untracked.
222
223       --status
224           Include the output of git-status(1) in the commit message template
225           when using an editor to prepare the commit message. Defaults to on,
226           but can be used to override configuration variable commit.status.
227
228       --no-status
229           Do not include the output of git-status(1) in the commit message
230           template when using an editor to prepare the default commit
231           message.
232
233       --
234           Do not interpret any more arguments as options.
235
236       <file>...
237           When files are given on the command line, the command commits the
238           contents of the named files, without recording the changes already
239           staged. The contents of these files are also staged for the next
240           commit on top of what have been staged before.
241

DATE FORMATS

243       The GIT_AUTHOR_DATE, GIT_COMMITTER_DATE environment variables and the
244       --date option support the following date formats:
245
246       Git internal format
247           It is <unix timestamp> <timezone offset>, where <unix timestamp> is
248           the number of seconds since the UNIX epoch.  <timezone offset> is a
249           positive or negative offset from UTC. For example CET (which is 2
250           hours ahead UTC) is +0200.
251
252       RFC 2822
253           The standard email format as described by RFC 2822, for example
254           Thu, 07 Apr 2005 22:13:13 +0200.
255
256       ISO 8601
257           Time and date specified by the ISO 8601 standard, for example
258           2005-04-07T22:13:13. The parser accepts a space instead of the T
259           character as well.
260
261               Note
262               In addition, the date part is accepted in the following
263               formats: YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY.
264

EXAMPLES

266       When recording your own work, the contents of modified files in your
267       working tree are temporarily stored to a staging area called the
268       "index" with git add. A file can be reverted back, only in the index
269       but not in the working tree, to that of the last commit with git reset
270       HEAD — <file>, which effectively reverts git add and prevents the
271       changes to this file from participating in the next commit. After
272       building the state to be committed incrementally with these commands,
273       git commit (without any pathname parameter) is used to record what has
274       been staged so far. This is the most basic form of the command. An
275       example:
276
277           $ edit hello.c
278           $ git rm goodbye.c
279           $ git add hello.c
280           $ git commit
281
282
283       Instead of staging files after each individual change, you can tell git
284       commit to notice the changes to the files whose contents are tracked in
285       your working tree and do corresponding git add and git rm for you. That
286       is, this example does the same as the earlier example if there is no
287       other change in your working tree:
288
289           $ edit hello.c
290           $ rm goodbye.c
291           $ git commit -a
292
293
294       The command git commit -a first looks at your working tree, notices
295       that you have modified hello.c and removed goodbye.c, and performs
296       necessary git add and git rm for you.
297
298       After staging changes to many files, you can alter the order the
299       changes are recorded in, by giving pathnames to git commit. When
300       pathnames are given, the command makes a commit that only records the
301       changes made to the named paths:
302
303           $ edit hello.c hello.h
304           $ git add hello.c hello.h
305           $ edit Makefile
306           $ git commit Makefile
307
308
309       This makes a commit that records the modification to Makefile. The
310       changes staged for hello.c and hello.h are not included in the
311       resulting commit. However, their changes are not lost — they are still
312       staged and merely held back. After the above sequence, if you do:
313
314           $ git commit
315
316
317       this second commit would record the changes to hello.c and hello.h as
318       expected.
319
320       After a merge (initiated by git merge or git pull) stops because of
321       conflicts, cleanly merged paths are already staged to be committed for
322       you, and paths that conflicted are left in unmerged state. You would
323       have to first check which paths are conflicting with git status and
324       after fixing them manually in your working tree, you would stage the
325       result as usual with git add:
326
327           $ git status | grep unmerged
328           unmerged: hello.c
329           $ edit hello.c
330           $ git add hello.c
331
332
333       After resolving conflicts and staging the result, git ls-files -u would
334       stop mentioning the conflicted path. When you are done, run git commit
335       to finally record the merge:
336
337           $ git commit
338
339
340       As with the case to record your own changes, you can use -a option to
341       save typing. One difference is that during a merge resolution, you
342       cannot use git commit with pathnames to alter the order the changes are
343       committed, because the merge should be recorded as a single commit. In
344       fact, the command refuses to run when given pathnames (but see -i
345       option).
346

DISCUSSION

348       Though not required, it’s a good idea to begin the commit message with
349       a single short (less than 50 character) line summarizing the change,
350       followed by a blank line and then a more thorough description. Tools
351       that turn commits into email, for example, use the first line on the
352       Subject: line and the rest of the commit in the body.
353
354       At the core level, git is character encoding agnostic.
355
356       ·   The pathnames recorded in the index and in the tree objects are
357           treated as uninterpreted sequences of non-NUL bytes. What
358           readdir(2) returns are what are recorded and compared with the data
359           git keeps track of, which in turn are expected to be what lstat(2)
360           and creat(2) accepts. There is no such thing as pathname encoding
361           translation.
362
363       ·   The contents of the blob objects are uninterpreted sequences of
364           bytes. There is no encoding translation at the core level.
365
366       ·   The commit log messages are uninterpreted sequences of non-NUL
367           bytes.
368
369       Although we encourage that the commit log messages are encoded in
370       UTF-8, both the core and git Porcelain are designed not to force UTF-8
371       on projects. If all participants of a particular project find it more
372       convenient to use legacy encodings, git does not forbid it. However,
373       there are a few things to keep in mind.
374
375        1.  git commit and git commit-tree issues a warning if the commit log
376           message given to it does not look like a valid UTF-8 string, unless
377           you explicitly say your project uses a legacy encoding. The way to
378           say this is to have i18n.commitencoding in .git/config file, like
379           this:
380
381               [i18n]
382                       commitencoding = ISO-8859-1
383
384           Commit objects created with the above setting record the value of
385           i18n.commitencoding in its encoding header. This is to help other
386           people who look at them later. Lack of this header implies that the
387           commit log message is encoded in UTF-8.
388
389        2.  git log, git show, git blame and friends look at the encoding
390           header of a commit object, and try to re-code the log message into
391           UTF-8 unless otherwise specified. You can specify the desired
392           output encoding with i18n.logoutputencoding in .git/config file,
393           like this:
394
395               [i18n]
396                       logoutputencoding = ISO-8859-1
397
398           If you do not have this configuration variable, the value of
399           i18n.commitencoding is used instead.
400
401       Note that we deliberately chose not to re-code the commit log message
402       when a commit is made to force UTF-8 at the commit object level,
403       because re-coding to UTF-8 is not necessarily a reversible operation.
404

ENVIRONMENT AND CONFIGURATION VARIABLES

406       The editor used to edit the commit log message will be chosen from the
407       GIT_EDITOR environment variable, the core.editor configuration
408       variable, the VISUAL environment variable, or the EDITOR environment
409       variable (in that order). See git-var(1) for details.
410

HOOKS

412       This command can run commit-msg, prepare-commit-msg, pre-commit, and
413       post-commit hooks. See githooks(5) for more information.
414

SEE ALSO

416       git-add(1), git-rm(1), git-mv(1), git-merge(1), git-commit-tree(1)
417

AUTHOR

419       Written by Linus Torvalds <torvalds@osdl.org[2]> and Junio C Hamano
420       <gitster@pobox.com[3]>
421

GIT

423       Part of the git(1) suite
424

NOTES

426        1. author@example.com
427           mailto:author@example.com
428
429        2. torvalds@osdl.org
430           mailto:torvalds@osdl.org
431
432        3. gitster@pobox.com
433           mailto:gitster@pobox.com
434
435
436
437Git 1.7.4.4                       04/11/2011                     GIT-COMMIT(1)
Impressum