1 git-commit(1)
2 =============
4 NAME
5 ----
6 git-commit - Record changes to the repository
8 SYNOPSIS
9 --------
10 [verse]
11 'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
12 [(-c | -C) <commit>] [-F <file> | -m <msg>] [--reset-author]
13 [--allow-empty] [--no-verify] [-e] [--author=<author>]
14 [--date=<date>] [--cleanup=<mode>] [--] [[-i | -o ]<file>...]
16 DESCRIPTION
17 -----------
18 Stores the current contents of the index in a new commit along
19 with a log message from the user describing the changes.
21 The content to be added can be specified in several ways:
23 1. by using 'git-add' to incrementally "add" changes to the
24 index before using the 'commit' command (Note: even modified
25 files must be "added");
27 2. by using 'git-rm' to remove files from the working tree
28 and the index, again before using the 'commit' command;
30 3. by listing files as arguments to the 'commit' command, in which
31 case 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);
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;
41 5. by using the --interactive switch with the 'commit' command to decide one
42 by one which files should be part of the commit, before finalizing the
43 operation. Currently, this is done by invoking 'git-add --interactive'.
45 The `--dry-run` option can be used to obtain a
46 summary of what is included by any of the above for the next
47 commit by giving the same set of parameters (options and paths).
49 If you make a commit and then find a mistake immediately after
50 that, you can recover from it with 'git-reset'.
53 OPTIONS
54 -------
55 -a::
56 --all::
57 Tell the command to automatically stage files that have
58 been modified and deleted, but new files you have not
59 told git about are not affected.
61 -C <commit>::
62 --reuse-message=<commit>::
63 Take an existing commit object, and reuse the log message
64 and the authorship information (including the timestamp)
65 when creating the commit.
67 -c <commit>::
68 --reedit-message=<commit>::
69 Like '-C', but with '-c' the editor is invoked, so that
70 the user can further edit the commit message.
72 --reset-author::
73 When used with -C/-c/--amend options, declare that the
74 authorship of the resulting commit now belongs of the committer.
75 This also renews the author timestamp.
77 -F <file>::
78 --file=<file>::
79 Take the commit message from the given file. Use '-' to
80 read the message from the standard input.
82 --author=<author>::
83 Override the author name used in the commit. You can use the
84 standard `A U Thor <author@example.com>` format. Otherwise,
85 an existing commit that matches the given string and its author
86 name is used.
88 --date=<date>::
89 Override the author date used in the commit.
91 -m <msg>::
92 --message=<msg>::
93 Use the given <msg> as the commit message.
95 -t <file>::
96 --template=<file>::
97 Use the contents of the given file as the initial version
98 of the commit message. The editor is invoked and you can
99 make subsequent changes. If a message is specified using
100 the `-m` or `-F` options, this option has no effect. This
101 overrides the `commit.template` configuration variable.
103 -s::
104 --signoff::
105 Add Signed-off-by line by the committer at the end of the commit
106 log message.
108 -n::
109 --no-verify::
110 This option bypasses the pre-commit and commit-msg hooks.
111 See also linkgit:githooks[5].
113 --allow-empty::
114 Usually recording a commit that has the exact same tree as its
115 sole parent commit is a mistake, and the command prevents you
116 from making such a commit. This option bypasses the safety, and
117 is primarily for use by foreign scm interface scripts.
119 --cleanup=<mode>::
120 This option sets how the commit message is cleaned up.
121 The '<mode>' can be one of 'verbatim', 'whitespace', 'strip',
122 and 'default'. The 'default' mode will strip leading and
123 trailing empty lines and #commentary from the commit message
124 only if the message is to be edited. Otherwise only whitespace
125 removed. The 'verbatim' mode does not change message at all,
126 'whitespace' removes just leading/trailing whitespace lines
127 and 'strip' removes both whitespace and commentary.
129 -e::
130 --edit::
131 The message taken from file with `-F`, command line with
132 `-m`, and from file with `-C` are usually used as the
133 commit log message unmodified. This option lets you
134 further edit the message taken from these sources.
136 --amend::
137 Used to amend the tip of the current branch. Prepare the tree
138 object you would want to replace the latest commit as usual
139 (this includes the usual -i/-o and explicit paths), and the
140 commit log editor is seeded with the commit message from the
141 tip of the current branch. The commit you create replaces the
142 current tip -- if it was a merge, it will have the parents of
143 the current tip as parents -- so the current top commit is
144 discarded.
145 +
146 --
147 It is a rough equivalent for:
148 ------
149 $ git reset --soft HEAD^
150 $ ... do something else to come up with the right tree ...
151 $ git commit -c ORIG_HEAD
153 ------
154 but can be used to amend a merge commit.
155 --
156 +
157 You should understand the implications of rewriting history if you
158 amend a commit that has already been published. (See the "RECOVERING
159 FROM UPSTREAM REBASE" section in linkgit:git-rebase[1].)
161 -i::
162 --include::
163 Before making a commit out of staged contents so far,
164 stage the contents of paths given on the command line
165 as well. This is usually not what you want unless you
166 are concluding a conflicted merge.
168 -o::
169 --only::
170 Make a commit only from the paths specified on the
171 command line, disregarding any contents that have been
172 staged so far. This is the default mode of operation of
173 'git-commit' if any paths are given on the command line,
174 in which case this option can be omitted.
175 If this option is specified together with '--amend', then
176 no paths need to be specified, which can be used to amend
177 the last commit without committing changes that have
178 already been staged.
180 -u[<mode>]::
181 --untracked-files[=<mode>]::
182 Show untracked files (Default: 'all').
183 +
184 The mode parameter is optional, and is used to specify
185 the handling of untracked files. The possible options are:
186 +
187 --
188 - 'no' - Show no untracked files
189 - 'normal' - Shows untracked files and directories
190 - 'all' - Also shows individual files in untracked directories.
191 --
192 +
193 See linkgit:git-config[1] for configuration variable
194 used to change the default for when the option is not
195 specified.
197 -v::
198 --verbose::
199 Show unified diff between the HEAD commit and what
200 would be committed at the bottom of the commit message
201 template. Note that this diff output doesn't have its
202 lines prefixed with '#'.
204 -q::
205 --quiet::
206 Suppress commit summary message.
208 --dry-run::
209 Do not create a commit, but show a list of paths that are
210 to be committed, paths with local changes that will be left
211 uncommitted and paths that are untracked.
213 \--::
214 Do not interpret any more arguments as options.
216 <file>...::
217 When files are given on the command line, the command
218 commits the contents of the named files, without
219 recording the changes already staged. The contents of
220 these files are also staged for the next commit on top
221 of what have been staged before.
223 :git-commit: 1
224 include::date-formats.txt[]
226 EXAMPLES
227 --------
228 When recording your own work, the contents of modified files in
229 your working tree are temporarily stored to a staging area
230 called the "index" with 'git-add'. A file can be
231 reverted back, only in the index but not in the working tree,
232 to that of the last commit with `git reset HEAD -- <file>`,
233 which effectively reverts 'git-add' and prevents the changes to
234 this file from participating in the next commit. After building
235 the state to be committed incrementally with these commands,
236 `git commit` (without any pathname parameter) is used to record what
237 has been staged so far. This is the most basic form of the
238 command. An example:
240 ------------
241 $ edit hello.c
242 $ git rm goodbye.c
243 $ git add hello.c
244 $ git commit
245 ------------
247 Instead of staging files after each individual change, you can
248 tell `git commit` to notice the changes to the files whose
249 contents are tracked in
250 your working tree and do corresponding `git add` and `git rm`
251 for you. That is, this example does the same as the earlier
252 example if there is no other change in your working tree:
254 ------------
255 $ edit hello.c
256 $ rm goodbye.c
257 $ git commit -a
258 ------------
260 The command `git commit -a` first looks at your working tree,
261 notices that you have modified hello.c and removed goodbye.c,
262 and performs necessary `git add` and `git rm` for you.
264 After staging changes to many files, you can alter the order the
265 changes are recorded in, by giving pathnames to `git commit`.
266 When pathnames are given, the command makes a commit that
267 only records the changes made to the named paths:
269 ------------
270 $ edit hello.c hello.h
271 $ git add hello.c hello.h
272 $ edit Makefile
273 $ git commit Makefile
274 ------------
276 This makes a commit that records the modification to `Makefile`.
277 The changes staged for `hello.c` and `hello.h` are not included
278 in the resulting commit. However, their changes are not lost --
279 they are still staged and merely held back. After the above
280 sequence, if you do:
282 ------------
283 $ git commit
284 ------------
286 this second commit would record the changes to `hello.c` and
287 `hello.h` as expected.
289 After a merge (initiated by 'git-merge' or 'git-pull') stops
290 because of conflicts, cleanly merged
291 paths are already staged to be committed for you, and paths that
292 conflicted are left in unmerged state. You would have to first
293 check which paths are conflicting with 'git-status'
294 and after fixing them manually in your working tree, you would
295 stage the result as usual with 'git-add':
297 ------------
298 $ git status | grep unmerged
299 unmerged: hello.c
300 $ edit hello.c
301 $ git add hello.c
302 ------------
304 After resolving conflicts and staging the result, `git ls-files -u`
305 would stop mentioning the conflicted path. When you are done,
306 run `git commit` to finally record the merge:
308 ------------
309 $ git commit
310 ------------
312 As with the case to record your own changes, you can use `-a`
313 option to save typing. One difference is that during a merge
314 resolution, you cannot use `git commit` with pathnames to
315 alter the order the changes are committed, because the merge
316 should be recorded as a single commit. In fact, the command
317 refuses to run when given pathnames (but see `-i` option).
320 DISCUSSION
321 ----------
323 Though not required, it's a good idea to begin the commit message
324 with a single short (less than 50 character) line summarizing the
325 change, followed by a blank line and then a more thorough description.
326 Tools that turn commits into email, for example, use the first line
327 on the Subject: line and the rest of the commit in the body.
329 include::i18n.txt[]
331 ENVIRONMENT AND CONFIGURATION VARIABLES
332 ---------------------------------------
333 The editor used to edit the commit log message will be chosen from the
334 GIT_EDITOR environment variable, the core.editor configuration variable, the
335 VISUAL environment variable, or the EDITOR environment variable (in that
336 order). See linkgit:git-var[1] for details.
338 HOOKS
339 -----
340 This command can run `commit-msg`, `prepare-commit-msg`, `pre-commit`,
341 and `post-commit` hooks. See linkgit:githooks[5] for more
342 information.
345 SEE ALSO
346 --------
347 linkgit:git-add[1],
348 linkgit:git-rm[1],
349 linkgit:git-mv[1],
350 linkgit:git-merge[1],
351 linkgit:git-commit-tree[1]
353 Author
354 ------
355 Written by Linus Torvalds <torvalds@osdl.org> and
356 Junio C Hamano <gitster@pobox.com>
359 GIT
360 ---
361 Part of the linkgit:git[1] suite