| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 1 | git-commit(1) |
| 2 | ============= |
| 3 | |
| 4 | NAME |
| 5 | ---- |
| 6 | git-commit - Record your changes |
| 7 | |
| 8 | SYNOPSIS |
| 9 | -------- |
| Junio C Hamano | 235a91e | 2006-01-07 01:13:58 | [diff] [blame] | 10 | [verse] |
| Junio C Hamano | 6697ac5 | 2006-02-14 08:00:23 | [diff] [blame] | 11 | 'git-commit' [-a] [-s] [-v] [(-c | -C) <commit> | -F <file> | -m <msg>] |
| Junio C Hamano | bfe9e75 | 2006-04-05 21:43:28 | [diff] [blame] | 12 | [--no-verify] [--amend] [-e] [--author <author>] |
| 13 | [--] [[-i | -o ]<file>...] |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 14 | |
| 15 | DESCRIPTION |
| 16 | ----------- |
| 17 | Updates the index file for given paths, or all modified files if |
| 18 | '-a' is specified, and makes a commit object. The command |
| 19 | VISUAL and EDITOR environment variables to edit the commit log |
| 20 | message. |
| 21 | |
| Junio C Hamano | 2b13527 | 2006-03-18 07:45:42 | [diff] [blame] | 22 | Several environment variable are used during commits. They are |
| 23 | documented in gitlink:git-commit-tree[1]. |
| 24 | |
| 25 | |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 26 | This command can run `commit-msg`, `pre-commit`, and |
| 27 | `post-commit` hooks. See link:hooks.html[hooks] for more |
| 28 | information. |
| 29 | |
| 30 | OPTIONS |
| 31 | ------- |
| 32 | -a|--all:: |
| Junio C Hamano | 74e8a2d | 2006-01-14 03:58:41 | [diff] [blame] | 33 | Update all paths in the index file. This flag notices |
| 34 | files that have been modified and deleted, but new files |
| Junio C Hamano | a6331a8 | 2006-01-22 07:50:33 | [diff] [blame] | 35 | you have not told git about are not affected. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 36 | |
| 37 | -c or -C <commit>:: |
| 38 | Take existing commit object, and reuse the log message |
| 39 | and the authorship information (including the timestamp) |
| 40 | when creating the commit. With '-C', the editor is not |
| 41 | invoked; with '-c' the user can further edit the commit |
| 42 | message. |
| 43 | |
| 44 | -F <file>:: |
| 45 | Take the commit message from the given file. Use '-' to |
| 46 | read the message from the standard input. |
| 47 | |
| Junio C Hamano | 40f2f8d | 2006-02-07 08:04:39 | [diff] [blame] | 48 | --author <author>:: |
| 49 | Override the author name used in the commit. Use |
| 50 | `A U Thor <author@example.com>` format. |
| 51 | |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 52 | -m <msg>:: |
| 53 | Use the given <msg> as the commit message. |
| 54 | |
| 55 | -s|--signoff:: |
| 56 | Add Signed-off-by line at the end of the commit message. |
| 57 | |
| 58 | -v|--verify:: |
| 59 | Look for suspicious lines the commit introduces, and |
| 60 | abort committing if there is one. The definition of |
| 61 | 'suspicious lines' is currently the lines that has |
| 62 | trailing whitespaces, and the lines whose indentation |
| 63 | has a SP character immediately followed by a TAB |
| 64 | character. This is the default. |
| 65 | |
| 66 | -n|--no-verify:: |
| 67 | The opposite of `--verify`. |
| 68 | |
| 69 | -e|--edit:: |
| 70 | The message taken from file with `-F`, command line with |
| 71 | `-m`, and from file with `-C` are usually used as the |
| 72 | commit log message unmodified. This option lets you |
| 73 | further edit the message taken from these sources. |
| 74 | |
| Junio C Hamano | bfe9e75 | 2006-04-05 21:43:28 | [diff] [blame] | 75 | --amend:: |
| 76 | |
| 77 | Used to amend the tip of the current branch. Prepare the tree |
| 78 | object you would want to replace the latest commit as usual |
| 79 | (this includes the usual -i/-o and explicit paths), and the |
| 80 | commit log editor is seeded with the commit message from the |
| 81 | tip of the current branch. The commit you create replaces the |
| 82 | current tip -- if it was a merge, it will have the parents of |
| 83 | the current tip as parents -- so the current top commit is |
| 84 | discarded. |
| 85 | + |
| Junio C Hamano | 47ea30e | 2006-04-05 23:08:03 | [diff] [blame^] | 86 | -- |
| Junio C Hamano | bfe9e75 | 2006-04-05 21:43:28 | [diff] [blame] | 87 | It is a rough equivalent for: |
| Junio C Hamano | 47ea30e | 2006-04-05 23:08:03 | [diff] [blame^] | 88 | ------ |
| Junio C Hamano | bfe9e75 | 2006-04-05 21:43:28 | [diff] [blame] | 89 | $ git reset --soft HEAD^ |
| 90 | $ ... do something else to come up with the right tree ... |
| 91 | $ git commit -c ORIG_HEAD |
| Junio C Hamano | 47ea30e | 2006-04-05 23:08:03 | [diff] [blame^] | 92 | |
| 93 | ------ |
| Junio C Hamano | bfe9e75 | 2006-04-05 21:43:28 | [diff] [blame] | 94 | but can be used to amend a merge commit. |
| Junio C Hamano | 47ea30e | 2006-04-05 23:08:03 | [diff] [blame^] | 95 | -- |
| Junio C Hamano | bfe9e75 | 2006-04-05 21:43:28 | [diff] [blame] | 96 | |
| Junio C Hamano | 40f2f8d | 2006-02-07 08:04:39 | [diff] [blame] | 97 | -i|--include:: |
| 98 | Instead of committing only the files specified on the |
| 99 | command line, update them in the index file and then |
| 100 | commit the whole index. This is the traditional |
| 101 | behaviour. |
| 102 | |
| Junio C Hamano | 6697ac5 | 2006-02-14 08:00:23 | [diff] [blame] | 103 | -o|--only:: |
| Junio C Hamano | 40f2f8d | 2006-02-07 08:04:39 | [diff] [blame] | 104 | Commit only the files specified on the command line. |
| 105 | This format cannot be used during a merge, nor when the |
| 106 | index and the latest commit does not match on the |
| 107 | specified paths to avoid confusion. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 108 | |
| Junio C Hamano | 6697ac5 | 2006-02-14 08:00:23 | [diff] [blame] | 109 | --:: |
| 110 | Do not interpret any more arguments as options. |
| 111 | |
| 112 | <file>...:: |
| 113 | Files to be committed. The meaning of these is |
| 114 | different between `--include` and `--only`. Without |
| 115 | either, it defaults `--only` semantics. |
| 116 | |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 117 | If you make a commit and then found a mistake immediately after |
| 118 | that, you can recover from it with gitlink:git-reset[1]. |
| 119 | |
| 120 | |
| Junio C Hamano | 40f2f8d | 2006-02-07 08:04:39 | [diff] [blame] | 121 | Discussion |
| 122 | ---------- |
| 123 | |
| 124 | `git commit` without _any_ parameter commits the tree structure |
| 125 | recorded by the current index file. This is a whole-tree commit |
| 126 | even the command is invoked from a subdirectory. |
| 127 | |
| 128 | `git commit --include paths...` is equivalent to |
| 129 | |
| 130 | git update-index --remove paths... |
| 131 | git commit |
| 132 | |
| 133 | That is, update the specified paths to the index and then commit |
| 134 | the whole tree. |
| 135 | |
| 136 | `git commit paths...` largely bypasses the index file and |
| 137 | commits only the changes made to the specified paths. It has |
| 138 | however several safety valves to prevent confusion. |
| 139 | |
| 140 | . It refuses to run during a merge (i.e. when |
| 141 | `$GIT_DIR/MERGE_HEAD` exists), and reminds trained git users |
| 142 | that the traditional semantics now needs -i flag. |
| 143 | |
| 144 | . It refuses to run if named `paths...` are different in HEAD |
| 145 | and the index (ditto about reminding). Added paths are OK. |
| 146 | This is because an earlier `git diff` (not `git diff HEAD`) |
| 147 | would have shown the differences since the last `git |
| 148 | update-index paths...` to the user, and an inexperienced user |
| 149 | may mistakenly think that the changes between the index and |
| 150 | the HEAD (i.e. earlier changes made before the last `git |
| 151 | update-index paths...` was done) are not being committed. |
| 152 | |
| 153 | . It reads HEAD commit into a temporary index file, updates the |
| 154 | specified `paths...` and makes a commit. At the same time, |
| 155 | the real index file is also updated with the same `paths...`. |
| 156 | |
| 157 | `git commit --all` updates the index file with _all_ changes to |
| 158 | the working tree, and makes a whole-tree commit, regardless of |
| 159 | which subdirectory the command is invoked in. |
| 160 | |
| 161 | |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 162 | Author |
| 163 | ------ |
| 164 | Written by Linus Torvalds <torvalds@osdl.org> and |
| 165 | Junio C Hamano <junkio@cox.net> |
| 166 | |
| 167 | |
| 168 | GIT |
| 169 | --- |
| 170 | Part of the gitlink:git[7] suite |