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] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
10 [(-c | -C) <commit>] [-F <file> | -m <msg>] [--reset-author]
11 [--allow-empty] [--no-verify] [-e] [--author=<author>]
12 [--date=<date>] [--cleanup=<mode>] [--status | --no-status] [--]
13 [[-i | -o ]<file>...]
14
15
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
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 --reset-author
68 When used with -C/-c/--amend options, declare that the authorship
69 of the resulting commit now belongs of the committer. This also
70 renews the author timestamp.
71
72 --short
73 When doing a dry-run, give the output in the short-format. See git-
74 status(1) for details. Implies --dry-run.
75
76 --porcelain
77 When doing a dry-run, give the output in a porcelain-ready format.
78 See git-status(1) for details. Implies --dry-run.
79
80 -z
81 When showing short or porcelain status output, terminate entries in
82 the status output with NUL, instead of LF. If no format is given,
83 implies the --porcelain output format.
84
85 -F <file>, --file=<file>
86 Take the commit message from the given file. Use - to read the
87 message from the standard input.
88
89 --author=<author>
90 Override the author name used in the commit. You can use the
91 standard A U Thor <author@example.com[1]> format. Otherwise, an
92 existing commit that matches the given string and its author name
93 is used.
94
95 --date=<date>
96 Override the author date used in the commit.
97
98 -m <msg>, --message=<msg>
99 Use the given <msg> as the commit message.
100
101 -t <file>, --template=<file>
102 Use the contents of the given file as the initial version of the
103 commit message. The editor is invoked and you can make subsequent
104 changes. If a message is specified using the -m or -F options, this
105 option has no effect. This overrides the commit.template
106 configuration variable.
107
108 -s, --signoff
109 Add Signed-off-by line by the committer at the end of the commit
110 log message.
111
112 -n, --no-verify
113 This option bypasses the pre-commit and commit-msg hooks. See also
114 githooks(5).
115
116 --allow-empty
117 Usually recording a commit that has the exact same tree as its sole
118 parent commit is a mistake, and the command prevents you from
119 making such a commit. This option bypasses the safety, and is
120 primarily for use by foreign scm interface scripts.
121
122 --cleanup=<mode>
123 This option sets how the commit message is cleaned up. The <mode>
124 can be one of verbatim, whitespace, strip, and default. The default
125 mode will strip leading and trailing empty lines and #commentary
126 from the commit message only if the message is to be edited.
127 Otherwise only whitespace removed. The verbatim mode does not
128 change message at all, whitespace removes just leading/trailing
129 whitespace lines and strip removes both whitespace and commentary.
130
131 -e, --edit
132 The message taken from file with -F, command line with -m, and from
133 file with -C are usually used as the commit log message unmodified.
134 This option lets you further edit the message taken from these
135 sources.
136
137 --amend
138 Used to amend the tip of the current branch. Prepare the tree
139 object you would want to replace the latest commit as usual (this
140 includes the usual -i/-o and explicit paths), and the commit log
141 editor is seeded with the commit message from the tip of the
142 current branch. The commit you create replaces the current tip — if
143 it was a merge, it will have the parents of the current tip as
144 parents — so the current top commit is discarded.
145
146 It is a rough equivalent for:
147
148 $ git reset --soft HEAD^
149 $ ... do something else to come up with the right tree ...
150 $ git commit -c ORIG_HEAD
151
152 but can be used to amend a merge commit.
153
154 You should understand the implications of rewriting history if you
155 amend a commit that has already been published. (See the
156 "RECOVERING FROM UPSTREAM REBASE" section in git-rebase(1).)
157
158 -i, --include
159 Before making a commit out of staged contents so far, stage the
160 contents of paths given on the command line as well. This is
161 usually not what you want unless you are concluding a conflicted
162 merge.
163
164 -o, --only
165 Make a commit only from the paths specified on the command line,
166 disregarding any contents that have been staged so far. This is the
167 default mode of operation of git commit if any paths are given on
168 the command line, in which case this option can be omitted. If this
169 option is specified together with --amend, then no paths need to be
170 specified, which can be used to amend the last commit without
171 committing changes that have already been staged.
172
173 -u[<mode>], --untracked-files[=<mode>]
174 Show untracked files (Default: all).
175
176 The mode parameter is optional, and is used to specify the handling
177 of untracked files.
178
179 The possible options are:
180
181 · no - Show no untracked files
182
183 · normal - Shows untracked files and directories
184
185 · all - Also shows individual files in untracked directories.
186
187 See git-config(1) for configuration variable used to change the
188 default for when the option is not specified.
189
190 -v, --verbose
191 Show unified diff between the HEAD commit and what would be
192 committed at the bottom of the commit message template. Note that
193 this diff output doesn’t have its lines prefixed with #.
194
195 -q, --quiet
196 Suppress commit summary message.
197
198 --dry-run
199 Do not create a commit, but show a list of paths that are to be
200 committed, paths with local changes that will be left uncommitted
201 and paths that are untracked.
202
203 --status
204 Include the output of git-status(1) in the commit message template
205 when using an editor to prepare the commit message. Defaults to on,
206 but can be used to override configuration variable commit.status.
207
208 --no-status
209 Do not include the output of git-status(1) in the commit message
210 template when using an editor to prepare the default commit
211 message.
212
213 --
214 Do not interpret any more arguments as options.
215
216 <file>...
217 When files are given on the command line, the command commits the
218 contents of the named files, without recording the changes already
219 staged. The contents of these files are also staged for the next
220 commit on top of what have been staged before.
221
223 The GIT_AUTHOR_DATE, GIT_COMMITTER_DATE environment variables and the
224 --date option support the following date formats:
225
226 Git internal format
227 It is <unix timestamp> <timezone offset>, where <unix timestamp> is
228 the number of seconds since the UNIX epoch. <timezone offset> is a
229 positive or negative offset from UTC. For example CET (which is 2
230 hours ahead UTC) is +0200.
231
232 RFC 2822
233 The standard email format as described by RFC 2822, for example
234 Thu, 07 Apr 2005 22:13:13 +0200.
235
236 ISO 8601
237 Time and date specified by the ISO 8601 standard, for example
238 2005-04-07T22:13:13. The parser accepts a space instead of the T
239 character as well.
240
241 Note
242 In addition, the date part is accepted in the following
243 formats: YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY.
244
246 When recording your own work, the contents of modified files in your
247 working tree are temporarily stored to a staging area called the
248 "index" with git add. A file can be reverted back, only in the index
249 but not in the working tree, to that of the last commit with git reset
250 HEAD — <file>, which effectively reverts git add and prevents the
251 changes to this file from participating in the next commit. After
252 building the state to be committed incrementally with these commands,
253 git commit (without any pathname parameter) is used to record what has
254 been staged so far. This is the most basic form of the command. An
255 example:
256
257 $ edit hello.c
258 $ git rm goodbye.c
259 $ git add hello.c
260 $ git commit
261
262
263 Instead of staging files after each individual change, you can tell git
264 commit to notice the changes to the files whose contents are tracked in
265 your working tree and do corresponding git add and git rm for you. That
266 is, this example does the same as the earlier example if there is no
267 other change in your working tree:
268
269 $ edit hello.c
270 $ rm goodbye.c
271 $ git commit -a
272
273
274 The command git commit -a first looks at your working tree, notices
275 that you have modified hello.c and removed goodbye.c, and performs
276 necessary git add and git rm for you.
277
278 After staging changes to many files, you can alter the order the
279 changes are recorded in, by giving pathnames to git commit. When
280 pathnames are given, the command makes a commit that only records the
281 changes made to the named paths:
282
283 $ edit hello.c hello.h
284 $ git add hello.c hello.h
285 $ edit Makefile
286 $ git commit Makefile
287
288
289 This makes a commit that records the modification to Makefile. The
290 changes staged for hello.c and hello.h are not included in the
291 resulting commit. However, their changes are not lost — they are still
292 staged and merely held back. After the above sequence, if you do:
293
294 $ git commit
295
296
297 this second commit would record the changes to hello.c and hello.h as
298 expected.
299
300 After a merge (initiated by git merge or git pull) stops because of
301 conflicts, cleanly merged paths are already staged to be committed for
302 you, and paths that conflicted are left in unmerged state. You would
303 have to first check which paths are conflicting with git status and
304 after fixing them manually in your working tree, you would stage the
305 result as usual with git add:
306
307 $ git status | grep unmerged
308 unmerged: hello.c
309 $ edit hello.c
310 $ git add hello.c
311
312
313 After resolving conflicts and staging the result, git ls-files -u would
314 stop mentioning the conflicted path. When you are done, run git commit
315 to finally record the merge:
316
317 $ git commit
318
319
320 As with the case to record your own changes, you can use -a option to
321 save typing. One difference is that during a merge resolution, you
322 cannot use git commit with pathnames to alter the order the changes are
323 committed, because the merge should be recorded as a single commit. In
324 fact, the command refuses to run when given pathnames (but see -i
325 option).
326
328 Though not required, it’s a good idea to begin the commit message with
329 a single short (less than 50 character) line summarizing the change,
330 followed by a blank line and then a more thorough description. Tools
331 that turn commits into email, for example, use the first line on the
332 Subject: line and the rest of the commit in the body.
333
334 At the core level, git is character encoding agnostic.
335
336 · The pathnames recorded in the index and in the tree objects are
337 treated as uninterpreted sequences of non-NUL bytes. What
338 readdir(2) returns are what are recorded and compared with the data
339 git keeps track of, which in turn are expected to be what lstat(2)
340 and creat(2) accepts. There is no such thing as pathname encoding
341 translation.
342
343 · The contents of the blob objects are uninterpreted sequences of
344 bytes. There is no encoding translation at the core level.
345
346 · The commit log messages are uninterpreted sequences of non-NUL
347 bytes.
348
349 Although we encourage that the commit log messages are encoded in
350 UTF-8, both the core and git Porcelain are designed not to force UTF-8
351 on projects. If all participants of a particular project find it more
352 convenient to use legacy encodings, git does not forbid it. However,
353 there are a few things to keep in mind.
354
355 1. git commit and git commit-tree issues a warning if the commit log
356 message given to it does not look like a valid UTF-8 string, unless
357 you explicitly say your project uses a legacy encoding. The way to
358 say this is to have i18n.commitencoding in .git/config file, like
359 this:
360
361 [i18n]
362 commitencoding = ISO-8859-1
363
364 Commit objects created with the above setting record the value of
365 i18n.commitencoding in its encoding header. This is to help other
366 people who look at them later. Lack of this header implies that the
367 commit log message is encoded in UTF-8.
368
369 2. git log, git show, git blame and friends look at the encoding
370 header of a commit object, and try to re-code the log message into
371 UTF-8 unless otherwise specified. You can specify the desired
372 output encoding with i18n.logoutputencoding in .git/config file,
373 like this:
374
375 [i18n]
376 logoutputencoding = ISO-8859-1
377
378 If you do not have this configuration variable, the value of
379 i18n.commitencoding is used instead.
380
381 Note that we deliberately chose not to re-code the commit log message
382 when a commit is made to force UTF-8 at the commit object level,
383 because re-coding to UTF-8 is not necessarily a reversible operation.
384
386 The editor used to edit the commit log message will be chosen from the
387 GIT_EDITOR environment variable, the core.editor configuration
388 variable, the VISUAL environment variable, or the EDITOR environment
389 variable (in that order). See git-var(1) for details.
390
392 This command can run commit-msg, prepare-commit-msg, pre-commit, and
393 post-commit hooks. See githooks(5) for more information.
394
396 git-add(1), git-rm(1), git-mv(1), git-merge(1), git-commit-tree(1)
397
399 Written by Linus Torvalds <torvalds@osdl.org[2]> and Junio C Hamano
400 <gitster@pobox.com[3]>
401
403 Part of the git(1) suite
404
406 1. author@example.com
407 mailto:author@example.com
408
409 2. torvalds@osdl.org
410 mailto:torvalds@osdl.org
411
412 3. gitster@pobox.com
413 mailto:gitster@pobox.com
414
415
416
417Git 1.7.1 08/16/2017 GIT-COMMIT(1)