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