git commit,提交改变到仓库
语法
git commit [-F <file> | -m <msg>] [<files>...]
描述
提交暂存区的或者改动的文件到仓库。
要添加的内容有几种来源:
1 暂存区。
2 命令行参数指定的文件。
选项:
-a
-all
自动暂存那些修改和删除的文件,但是新文件不会被暂存,注意:
新的,删除的,修改的
是相对于当前index来说的,不是相对于最后一次commit来说的。git add命令也是如此。
-C <commit>
--reuse-message=<commit>
使用之前的commit的log message和作者信息以及时间戳创建本次commit。
-c <commit>
--reedit-message=<commit>
和-C一样,但是启动一个编辑器来编辑log。
--short
dry-run的时候显示简短格式:
1 2 | $ git commit . --dry-run --short A a |
-F <file>
--file=<file>
指定log消息的文件。
--author=<author>
指定作者。格式author<author@example.com>
-m <msg>
--message=<msg>
指定日志。
--amend
创建新的commit替换当前分支的最新commit。
-u[<mode>]
--untracked-files[=<mode>]
如何显示untracked files。
--dry-run
和git add的--dry-run是类似的,不做实际的提交动作,只显示要提交的内容。会显示暂存区的,工作区未暂存的,untracked的信息。可以使用-u来控制显示untracked的文件。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | $ git commit --dry-run On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: b Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: a Untracked files: (use "git add <file>..." to include in what will be committed) c |
<file>...
当命令行中指定了文件后,只将这些指定的文件提交到仓库。被暂存的文件不会提交,新提交的文件也会丢到暂存区。
等价于没有暂存,然后git add这些文件,然后commit,然后在暂存之前暂存的文件。
只执行git commit,不带任何参数,如果暂存区有更新则打开一个编辑器,编辑日志后提交。如果暂存区没有更新,则相当于dry run,显示工作区的状态。
参考:
https://git-scm.com/docs/git-commit