Git 每次提交代码,都要写 Commit message(提交说明),否则就不允许提交。
1 | git commit -m "hello world" |
如果不写 -m 及后面的信息, 命令行会进入 vim 模式, 让你输入详细的 commit 信息
一般来说, commit 信息应该清晰明了,
按照 Angular 开发团队的代码提交规范
- [feat]: A new feature
- [fix]: A bug fix
- [docs]: Documentation only changes
- [style]: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
- [refactor]: A code change that neither fixes a bug nor adds a feature
- [perf]: A code change that improves performance
- [test]: Adding missing or correcting existing tests
- [chore]: Changes to the build process or auxiliary tools and libraries such as documentation generation
详情可 参考此处
Commit message 的作用
格式化的Commit message,有几个好处。
(1)提供更多的历史信息,方便快速浏览。
可以用以下命令来 快速的查看 commit message 的相关信息
1 | git log --pretty=format:"%C(auto)%h %ad | %C(auto)%s%d %Cblue(%an)" --date=short |
(2)可以过滤某些commit(比如文档改动),便于快速查找信息。
(3)可以直接从commit生成Change log。
Commit message 的格式
每次提交,Commit message 都包括三个部分:Header,Body 和 Footer。
1 | <type>(<scope>): <subject> |
其中,Header 是必需的,Body 和 Footer 可以省略。
不管是哪一个部分,任何一行都不得超过72个字符(或100个字符)。这是为了避免自动换行影响美观。
生成 Change log
conventional-changelog 就是生成 Change log 的工具,运行下面的命令即可。
1 | npm install -g conventional-changelog |
如果你想生成所有发布的 Change log,要改为运行下面的命令。
1 | conventional-changelog -p angular -i CHANGELOG.md -w -r 0 |
reference
https://github.com/angular/angular/commits/master
http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Kwin 's Blog!
评论