git-commit.txt 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. git-commit(1)
  2. =============
  3. NAME
  4. ----
  5. git-commit - Record changes to the repository
  6. SYNOPSIS
  7. --------
  8. [verse]
  9. 'git commit' [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend]
  10. [--dry-run] [(-c | -C | --fixup | --squash) <commit>]
  11. [-F <file> | -m <msg>] [--reset-author] [--allow-empty]
  12. [--allow-empty-message] [--no-verify] [-e] [--author=<author>]
  13. [--date=<date>] [--cleanup=<mode>] [--[no-]status]
  14. [-i | -o] [--pathspec-from-file=<file> [--pathspec-file-nul]]
  15. [-S[<keyid>]] [--] [<pathspec>...]
  16. DESCRIPTION
  17. -----------
  18. Create a new commit containing the current contents of the index and
  19. the given log message describing the changes. The new commit is a
  20. direct child of HEAD, usually the tip of the current branch, and the
  21. branch is updated to point to it (unless no branch is associated with
  22. the working tree, in which case HEAD is "detached" as described in
  23. linkgit:git-checkout[1]).
  24. The content to be committed can be specified in several ways:
  25. 1. by using linkgit:git-add[1] to incrementally "add" changes to the
  26. index before using the 'commit' command (Note: even modified files
  27. must be "added");
  28. 2. by using linkgit:git-rm[1] to remove files from the working tree
  29. and the index, again before using the 'commit' command;
  30. 3. by listing files as arguments to the 'commit' command
  31. (without --interactive or --patch switch), 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. 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;
  40. 5. by using the --interactive or --patch switches with the 'commit' command
  41. to decide one by one which files or hunks should be part of the commit
  42. in addition to contents in the index,
  43. before finalizing the operation. See the ``Interactive Mode'' section of
  44. linkgit:git-add[1] to learn how to operate these modes.
  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).
  48. If you make a commit and then find a mistake immediately after
  49. that, you can recover from it with 'git reset'.
  50. OPTIONS
  51. -------
  52. -a::
  53. --all::
  54. Tell the command to automatically stage files that have
  55. been modified and deleted, but new files you have not
  56. told Git about are not affected.
  57. -p::
  58. --patch::
  59. Use the interactive patch selection interface to chose
  60. which changes to commit. See linkgit:git-add[1] for
  61. details.
  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. -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.
  71. --fixup=<commit>::
  72. Construct a commit message for use with `rebase --autosquash`.
  73. The commit message will be the subject line from the specified
  74. commit with a prefix of "fixup! ". See linkgit:git-rebase[1]
  75. for details.
  76. --squash=<commit>::
  77. Construct a commit message for use with `rebase --autosquash`.
  78. The commit message subject line is taken from the specified
  79. commit with a prefix of "squash! ". Can be used with additional
  80. commit message options (`-m`/`-c`/`-C`/`-F`). See
  81. linkgit:git-rebase[1] for details.
  82. --reset-author::
  83. When used with -C/-c/--amend options, or when committing after a
  84. conflicting cherry-pick, declare that the authorship of the
  85. resulting commit now belongs to the committer. This also renews
  86. the author timestamp.
  87. --short::
  88. When doing a dry-run, give the output in the short-format. See
  89. linkgit:git-status[1] for details. Implies `--dry-run`.
  90. --branch::
  91. Show the branch and tracking info even in short-format.
  92. --porcelain::
  93. When doing a dry-run, give the output in a porcelain-ready
  94. format. See linkgit:git-status[1] for details. Implies
  95. `--dry-run`.
  96. --long::
  97. When doing a dry-run, give the output in the long-format.
  98. Implies `--dry-run`.
  99. -z::
  100. --null::
  101. When showing `short` or `porcelain` status output, print the
  102. filename verbatim and terminate the entries with NUL, instead of LF.
  103. If no format is given, implies the `--porcelain` output format.
  104. Without the `-z` option, filenames with "unusual" characters are
  105. quoted as explained for the configuration variable `core.quotePath`
  106. (see linkgit:git-config[1]).
  107. -F <file>::
  108. --file=<file>::
  109. Take the commit message from the given file. Use '-' to
  110. read the message from the standard input.
  111. --author=<author>::
  112. Override the commit author. Specify an explicit author using the
  113. standard `A U Thor <author@example.com>` format. Otherwise <author>
  114. is assumed to be a pattern and is used to search for an existing
  115. commit by that author (i.e. rev-list --all -i --author=<author>);
  116. the commit author is then copied from the first such commit found.
  117. --date=<date>::
  118. Override the author date used in the commit.
  119. -m <msg>::
  120. --message=<msg>::
  121. Use the given <msg> as the commit message.
  122. If multiple `-m` options are given, their values are
  123. concatenated as separate paragraphs.
  124. +
  125. The `-m` option is mutually exclusive with `-c`, `-C`, and `-F`.
  126. -t <file>::
  127. --template=<file>::
  128. When editing the commit message, start the editor with the
  129. contents in the given file. The `commit.template` configuration
  130. variable is often used to give this option implicitly to the
  131. command. This mechanism can be used by projects that want to
  132. guide participants with some hints on what to write in the message
  133. in what order. If the user exits the editor without editing the
  134. message, the commit is aborted. This has no effect when a message
  135. is given by other means, e.g. with the `-m` or `-F` options.
  136. -s::
  137. --signoff::
  138. Add Signed-off-by line by the committer at the end of the commit
  139. log message. The meaning of a signoff depends on the project,
  140. but it typically certifies that committer has
  141. the rights to submit this work under the same license and
  142. agrees to a Developer Certificate of Origin
  143. (see http://developercertificate.org/ for more information).
  144. -n::
  145. --no-verify::
  146. This option bypasses the pre-commit and commit-msg hooks.
  147. See also linkgit:githooks[5].
  148. --allow-empty::
  149. Usually recording a commit that has the exact same tree as its
  150. sole parent commit is a mistake, and the command prevents you
  151. from making such a commit. This option bypasses the safety, and
  152. is primarily for use by foreign SCM interface scripts.
  153. --allow-empty-message::
  154. Like --allow-empty this command is primarily for use by foreign
  155. SCM interface scripts. It allows you to create a commit with an
  156. empty commit message without using plumbing commands like
  157. linkgit:git-commit-tree[1].
  158. --cleanup=<mode>::
  159. This option determines how the supplied commit message should be
  160. cleaned up before committing. The '<mode>' can be `strip`,
  161. `whitespace`, `verbatim`, `scissors` or `default`.
  162. +
  163. --
  164. strip::
  165. Strip leading and trailing empty lines, trailing whitespace,
  166. commentary and collapse consecutive empty lines.
  167. whitespace::
  168. Same as `strip` except #commentary is not removed.
  169. verbatim::
  170. Do not change the message at all.
  171. scissors::
  172. Same as `whitespace` except that everything from (and including)
  173. the line found below is truncated, if the message is to be edited.
  174. "`#`" can be customized with core.commentChar.
  175. # ------------------------ >8 ------------------------
  176. default::
  177. Same as `strip` if the message is to be edited.
  178. Otherwise `whitespace`.
  179. --
  180. +
  181. The default can be changed by the `commit.cleanup` configuration
  182. variable (see linkgit:git-config[1]).
  183. -e::
  184. --edit::
  185. The message taken from file with `-F`, command line with
  186. `-m`, and from commit object with `-C` are usually used as
  187. the commit log message unmodified. This option lets you
  188. further edit the message taken from these sources.
  189. --no-edit::
  190. Use the selected commit message without launching an editor.
  191. For example, `git commit --amend --no-edit` amends a commit
  192. without changing its commit message.
  193. --amend::
  194. Replace the tip of the current branch by creating a new
  195. commit. The recorded tree is prepared as usual (including
  196. the effect of the `-i` and `-o` options and explicit
  197. pathspec), and the message from the original commit is used
  198. as the starting point, instead of an empty message, when no
  199. other message is specified from the command line via options
  200. such as `-m`, `-F`, `-c`, etc. The new commit has the same
  201. parents and author as the current one (the `--reset-author`
  202. option can countermand this).
  203. +
  204. --
  205. It is a rough equivalent for:
  206. ------
  207. $ git reset --soft HEAD^
  208. $ ... do something else to come up with the right tree ...
  209. $ git commit -c ORIG_HEAD
  210. ------
  211. but can be used to amend a merge commit.
  212. --
  213. +
  214. You should understand the implications of rewriting history if you
  215. amend a commit that has already been published. (See the "RECOVERING
  216. FROM UPSTREAM REBASE" section in linkgit:git-rebase[1].)
  217. --no-post-rewrite::
  218. Bypass the post-rewrite hook.
  219. -i::
  220. --include::
  221. Before making a commit out of staged contents so far,
  222. stage the contents of paths given on the command line
  223. as well. This is usually not what you want unless you
  224. are concluding a conflicted merge.
  225. -o::
  226. --only::
  227. Make a commit by taking the updated working tree contents
  228. of the paths specified on the
  229. command line, disregarding any contents that have been
  230. staged for other paths. This is the default mode of operation of
  231. 'git commit' if any paths are given on the command line,
  232. in which case this option can be omitted.
  233. If this option is specified together with `--amend`, then
  234. no paths need to be specified, which can be used to amend
  235. the last commit without committing changes that have
  236. already been staged. If used together with `--allow-empty`
  237. paths are also not required, and an empty commit will be created.
  238. --pathspec-from-file=<file>::
  239. Pathspec is passed in `<file>` instead of commandline args. If
  240. `<file>` is exactly `-` then standard input is used. Pathspec
  241. elements are separated by LF or CR/LF. Pathspec elements can be
  242. quoted as explained for the configuration variable `core.quotePath`
  243. (see linkgit:git-config[1]). See also `--pathspec-file-nul` and
  244. global `--literal-pathspecs`.
  245. --pathspec-file-nul::
  246. Only meaningful with `--pathspec-from-file`. Pathspec elements are
  247. separated with NUL character and all other characters are taken
  248. literally (including newlines and quotes).
  249. -u[<mode>]::
  250. --untracked-files[=<mode>]::
  251. Show untracked files.
  252. +
  253. --
  254. The mode parameter is optional (defaults to 'all'), and is used to
  255. specify the handling of untracked files; when -u is not used, the
  256. default is 'normal', i.e. show untracked files and directories.
  257. The possible options are:
  258. - 'no' - Show no untracked files
  259. - 'normal' - Shows untracked files and directories
  260. - 'all' - Also shows individual files in untracked directories.
  261. The default can be changed using the status.showUntrackedFiles
  262. configuration variable documented in linkgit:git-config[1].
  263. --
  264. -v::
  265. --verbose::
  266. Show unified diff between the HEAD commit and what
  267. would be committed at the bottom of the commit message
  268. template to help the user describe the commit by reminding
  269. what changes the commit has.
  270. Note that this diff output doesn't have its
  271. lines prefixed with '#'. This diff will not be a part
  272. of the commit message. See the `commit.verbose` configuration
  273. variable in linkgit:git-config[1].
  274. +
  275. If specified twice, show in addition the unified diff between
  276. what would be committed and the worktree files, i.e. the unstaged
  277. changes to tracked files.
  278. -q::
  279. --quiet::
  280. Suppress commit summary message.
  281. --dry-run::
  282. Do not create a commit, but show a list of paths that are
  283. to be committed, paths with local changes that will be left
  284. uncommitted and paths that are untracked.
  285. --status::
  286. Include the output of linkgit:git-status[1] in the commit
  287. message template when using an editor to prepare the commit
  288. message. Defaults to on, but can be used to override
  289. configuration variable commit.status.
  290. --no-status::
  291. Do not include the output of linkgit:git-status[1] in the
  292. commit message template when using an editor to prepare the
  293. default commit message.
  294. -S[<keyid>]::
  295. --gpg-sign[=<keyid>]::
  296. --no-gpg-sign::
  297. GPG-sign commits. The `keyid` argument is optional and
  298. defaults to the committer identity; if specified, it must be
  299. stuck to the option without a space. `--no-gpg-sign` is useful to
  300. countermand both `commit.gpgSign` configuration variable, and
  301. earlier `--gpg-sign`.
  302. \--::
  303. Do not interpret any more arguments as options.
  304. <pathspec>...::
  305. When pathspec is given on the command line, commit the contents of
  306. the files that match the pathspec without recording the changes
  307. already added to the index. The contents of these files are also
  308. staged for the next commit on top of what have been staged before.
  309. +
  310. For more details, see the 'pathspec' entry in linkgit:gitglossary[7].
  311. EXAMPLES
  312. --------
  313. When recording your own work, the contents of modified files in
  314. your working tree are temporarily stored to a staging area
  315. called the "index" with 'git add'. A file can be
  316. reverted back, only in the index but not in the working tree,
  317. to that of the last commit with `git restore --staged <file>`,
  318. which effectively reverts 'git add' and prevents the changes to
  319. this file from participating in the next commit. After building
  320. the state to be committed incrementally with these commands,
  321. `git commit` (without any pathname parameter) is used to record what
  322. has been staged so far. This is the most basic form of the
  323. command. An example:
  324. ------------
  325. $ edit hello.c
  326. $ git rm goodbye.c
  327. $ git add hello.c
  328. $ git commit
  329. ------------
  330. Instead of staging files after each individual change, you can
  331. tell `git commit` to notice the changes to the files whose
  332. contents are tracked in
  333. your working tree and do corresponding `git add` and `git rm`
  334. for you. That is, this example does the same as the earlier
  335. example if there is no other change in your working tree:
  336. ------------
  337. $ edit hello.c
  338. $ rm goodbye.c
  339. $ git commit -a
  340. ------------
  341. The command `git commit -a` first looks at your working tree,
  342. notices that you have modified hello.c and removed goodbye.c,
  343. and performs necessary `git add` and `git rm` for you.
  344. After staging changes to many files, you can alter the order the
  345. changes are recorded in, by giving pathnames to `git commit`.
  346. When pathnames are given, the command makes a commit that
  347. only records the changes made to the named paths:
  348. ------------
  349. $ edit hello.c hello.h
  350. $ git add hello.c hello.h
  351. $ edit Makefile
  352. $ git commit Makefile
  353. ------------
  354. This makes a commit that records the modification to `Makefile`.
  355. The changes staged for `hello.c` and `hello.h` are not included
  356. in the resulting commit. However, their changes are not lost --
  357. they are still staged and merely held back. After the above
  358. sequence, if you do:
  359. ------------
  360. $ git commit
  361. ------------
  362. this second commit would record the changes to `hello.c` and
  363. `hello.h` as expected.
  364. After a merge (initiated by 'git merge' or 'git pull') stops
  365. because of conflicts, cleanly merged
  366. paths are already staged to be committed for you, and paths that
  367. conflicted are left in unmerged state. You would have to first
  368. check which paths are conflicting with 'git status'
  369. and after fixing them manually in your working tree, you would
  370. stage the result as usual with 'git add':
  371. ------------
  372. $ git status | grep unmerged
  373. unmerged: hello.c
  374. $ edit hello.c
  375. $ git add hello.c
  376. ------------
  377. After resolving conflicts and staging the result, `git ls-files -u`
  378. would stop mentioning the conflicted path. When you are done,
  379. run `git commit` to finally record the merge:
  380. ------------
  381. $ git commit
  382. ------------
  383. As with the case to record your own changes, you can use `-a`
  384. option to save typing. One difference is that during a merge
  385. resolution, you cannot use `git commit` with pathnames to
  386. alter the order the changes are committed, because the merge
  387. should be recorded as a single commit. In fact, the command
  388. refuses to run when given pathnames (but see `-i` option).
  389. COMMIT INFORMATION
  390. ------------------
  391. Author and committer information is taken from the following environment
  392. variables, if set:
  393. GIT_AUTHOR_NAME
  394. GIT_AUTHOR_EMAIL
  395. GIT_AUTHOR_DATE
  396. GIT_COMMITTER_NAME
  397. GIT_COMMITTER_EMAIL
  398. GIT_COMMITTER_DATE
  399. (nb "<", ">" and "\n"s are stripped)
  400. The author and committer names are by convention some form of a personal name
  401. (that is, the name by which other humans refer to you), although Git does not
  402. enforce or require any particular form. Arbitrary Unicode may be used, subject
  403. to the constraints listed above. This name has no effect on authentication; for
  404. that, see the `credential.username` variable in linkgit:git-config[1].
  405. In case (some of) these environment variables are not set, the information
  406. is taken from the configuration items `user.name` and `user.email`, or, if not
  407. present, the environment variable EMAIL, or, if that is not set,
  408. system user name and the hostname used for outgoing mail (taken
  409. from `/etc/mailname` and falling back to the fully qualified hostname when
  410. that file does not exist).
  411. The `author.name` and `committer.name` and their corresponding email options
  412. override `user.name` and `user.email` if set and are overridden themselves by
  413. the environment variables.
  414. The typical usage is to set just the `user.name` and `user.email` variables;
  415. the other options are provided for more complex use cases.
  416. :git-commit: 1
  417. include::date-formats.txt[]
  418. DISCUSSION
  419. ----------
  420. Though not required, it's a good idea to begin the commit message
  421. with a single short (less than 50 character) line summarizing the
  422. change, followed by a blank line and then a more thorough description.
  423. The text up to the first blank line in a commit message is treated
  424. as the commit title, and that title is used throughout Git.
  425. For example, linkgit:git-format-patch[1] turns a commit into email, and it uses
  426. the title on the Subject line and the rest of the commit in the body.
  427. include::i18n.txt[]
  428. ENVIRONMENT AND CONFIGURATION VARIABLES
  429. ---------------------------------------
  430. The editor used to edit the commit log message will be chosen from the
  431. `GIT_EDITOR` environment variable, the core.editor configuration variable, the
  432. `VISUAL` environment variable, or the `EDITOR` environment variable (in that
  433. order). See linkgit:git-var[1] for details.
  434. HOOKS
  435. -----
  436. This command can run `commit-msg`, `prepare-commit-msg`, `pre-commit`,
  437. `post-commit` and `post-rewrite` hooks. See linkgit:githooks[5] for more
  438. information.
  439. FILES
  440. -----
  441. `$GIT_DIR/COMMIT_EDITMSG`::
  442. This file contains the commit message of a commit in progress.
  443. If `git commit` exits due to an error before creating a commit,
  444. any commit message that has been provided by the user (e.g., in
  445. an editor session) will be available in this file, but will be
  446. overwritten by the next invocation of `git commit`.
  447. SEE ALSO
  448. --------
  449. linkgit:git-add[1],
  450. linkgit:git-rm[1],
  451. linkgit:git-mv[1],
  452. linkgit:git-merge[1],
  453. linkgit:git-commit-tree[1]
  454. GIT
  455. ---
  456. Part of the linkgit:git[1] suite