一个Git Commit Message模板
一个统一的commit消息模板可以约束团队成员使用一致的方式提交变更信息,这样也方便集成工具进行合规检查。 通常来讲,commit信息应该包含如下内容:
<type>(<scope>): <subject> <BLANK LINE> <body> <BLANK LINE> <footer>
type表示commit类型,可选值如下: 1.feat: A new feature 2.fix: A bug fix 3.docs: Documentation only changes 4.style: Changes that do not affect the meaning of the code (white-space, formatting, etc) 5.refactor: A code change that neither fixes a bug nor adds a feature 6.perf: A code change that improves performance 7.test: Adding missing tests or correcting existing tests 8.build: Changes that affect the build system or external dependencies (e.g: gulp, npm) 9.ci:Changes to our CI configuration files and scripts (e.g: Travis, Circle, BrowserStack) 10.chore: Other changes that don’t modify src or test files 11.revert: Reverts a previous commit
scope表示影响范围,如:route, component, utils, build等 subject表示commit概述,建议符合 body表示具体修改的内容,可以分为多行,每一行建议符合 footer是一些备注信息, 通常是BREAKING CHANGE或修复的BUG链接,如:issue #123
变更消息模板可以通过文件的方式固话下来,这样在每次提交变更的时候参照模板填写对应的信息。 一个完整的模板内容如下:
# head: <type>(<scope>): <subject> # - type: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert # - scope: can be empty (eg. if the change is a global or difficult to assign to a single component), e.g: route, component, utils, build... # - subject: start with verb (such as change), 50-character line # # body: 72-character wrapped. Multiple lines separated by “-”, This should answer: # * Why was this change necessary? # * How does it address the problem? # * Are there any side effects? # # footer: # - Include a link to the ticket, if any. # - BREAKING CHANGE # # e.g: # <type>(<scope>): <subject> # <BLANK LINE> # <body> # <BLANK LINE> # <footer> # # types: # # 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 tests or correcting existing tests # 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) # chore: Other changes that dont modify src or test files # revert: Reverts a previous commit
可以将上述模板信息保存在文件"~/.gitmessage "中并添加为git的commit模板: 修改 ~/.gitconfig,添加:
[commit] template = ~/.gitmessage