据我了解,目前使用比较多的是 angular 规范,相关介绍文章:
- Conventional Commits
- angular/CONTRIBUTING.md at 22b96b96902e1a42ee8c5e807720424abad3082a · angular/angular · GitHub
- Karma - Git Commit Msg
它的 commit message 格式为:
<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
概括起来就是 header, body, fotter 三部分。其中 body 和 footer 可选。
header 只有一行,它又分为三部分:
- type: 提交类型,有如下定义
- build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
- ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
- docs: Documentation only changes
- feat: A new feature
- fix: A bug fix
- perf: A code change that improves performance
- refactor: A code change that neither fixes a bug nor adds a feature
- style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
- test: Adding missing tests or correcting existing tests
- scope: 影响范围,可选。
- subject: 简短描述,以动词开头,长度不超过 50
总体看起来不错,但有时又觉得别扭,例如当提交 fix
类型的时候,就不好用 Fix 来描述修改了:fix: Fix
。
另外还规定必须在 footer 关闭 issue,所以 angular 仓库就能看到大量类似这样冗余的写法:
docs: the token should be associated with LibHeaderComponent (#40922)
PR Close #40922
一个 issue 号写了两遍。
其他书写规范:
1
https://docs.typo3.org/m/typo3/guide-contributionworkflow/master/en-us/Appendix/CommitMessage.html
Some examples of topic descriptions
[BUGFIX] Throw HttpStatusExceptions in BackendController [FEATURE] Add option to hide BE search box in list mod [!!!][FEATURE] Implement new BE login form service [!!!][TASK] Replace Foo API with new approach [SECURITY] Escape record title in RecordsOverview
Note: The [!!!] prefix is added at the very beginning of the line, so it doesn’t get overlooked.
这个也必须在 footer 里边关闭 issue。
2
Here’s my commit message template:
## If applied, this commit will... ## [Add/Fix/Remove/Update/Refactor/Document] [issue #id] [summary] ## Why is it necessary? (Bug fix, feature, improvements?) - ## How does the change address the issue? - ## What side effects does this change have? -
… and it comes out looking something like this:
Fix #16 missing CSS variables - Fix for unstyled elements - Add background color, height for code blocks - Only affects highlight class
这个似乎不错,Fix 即表示类型又当动词用(不用想别的替代动词),一行就可以关闭 issue。而且不用冒号/括号,看起来比较自然。
3
I use
[Abc]: Message.
With Add, Mod(ify), Ref(actoring), Fix, Rem(ove) and Rea(dability) then it’s easy to extract logfile.
Example :
Add: New function to rule the world. Mod: Add women factor in Domination.ruleTheWorld(). Ref: Extract empathy stuff to an abstract class. Fix: RUL-42 or #42 Starvation need to be initialised before Energy to avoid the nullpointer in People. Rem: freeSpeech is not used anymore. Rea: Removed old TODO and extra space in header.
这个也挺简洁。
4
We use the following:
[Ticket's Id in JIRA]: [Message: What was done] For example - ABC-123: Added ability to configure presentation per region.
In this case with proper integration you will be able to get changed/deleted/added files in your issue tracker. However, be aware that you should prevent something like ABC-123: Done or ABC-123: Fixed with filters if possible.
这个略为死板,提交 feature 之前必须先开 ticket。
这个答案下边有人给出了类似的规范:
[ticketId][ABC][topicId][WIP] Message, where:
ticketId - id of an item in task repository ABC - add (feature), fix (bugfix), str (structure), dep (dependency) rem (backward incompatibility/remove), rea (readability), ref (refactoring) topicId - can be a job selector for jenkins and/or branch name and/or topic name for gerrit WIP - work in progress/or not (i.e. Continuous Integration may requires this) message - detail of the modification
Examples:
[#452567][add][menu_item] new item - guestbook [#452363][fix][banner_top][WIP] 1024x300 can be used now [#452363][fix][banner_top] 500x200 can be used now [#452713][rem][page] left middle ad