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