git commit
git
用法
git commit [-a] -m "<message>"把暂存区里的内容记成一个提交;-a 只会带上已跟踪文件的改动,新建的文件不算。
常用选项
| 选项 | 含义 |
|---|---|
| -m "<msg>" | give the message on the command line |
| -a | stage modified tracked files first; new files are skipped |
| --amend | replace the previous commit instead of adding one |
| --no-edit | keep the old message, used with --amend |
| --fixup=<commit> | mark it to be folded into <commit> by rebase --autosquash |
| -S | sign the commit with GPG |
| --allow-empty | commit with nothing staged |
示例
git commit -m "fix login redirect"records what is staged
git commit -a -m "typo"stages tracked edits and commits in one step
git commit --amend --no-editfolds the staged change into the last commit, keeping its message
难的地方在于撤销有好几种:把分支的指向挪走,和补一个反向提交,不是一回事。
怎么看
- 方括号 [ ] 表示这部分可以不写。
- 省略号 … 表示可以写多个。
- 选项区分大小写——有些命令里 -r 和 -R 不是一回事。
常见问题
Q. git commit 是做什么的?
把暂存区里的内容记成一个提交;-a 只会带上已跟踪文件的改动,新建的文件不算。
Q. 怎么写?
git commit [-a] -m "<message>" —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 7 个,完整列表在 man git。这条命令属于git。
相关命令
man 手册: man git-commit