如何将git commit日志规范化,以提升代码质量和团队协作效率?
摘要:一、作用 编写格式化的 commit message 能够大大提高代码的维护效率。 比如: 可以提供更多的历史信息,方便快速浏览; 可以过滤某些 commit(比
一、作用
编写格式化的commit message能够大大提高代码的维护效率。
比如:
可以提供更多的历史信息,方便快速浏览;
可以过滤某些commit(比如文档改动),便于快速查找信息;
可以直接从commit生成Change log;
二、Commit message 的格式
每次提交,Commit message 都包括三个部分:Message header,Message body 和 Message footer。
< type >(< scope >):< subject > //header内容
//空一行
< body > //body内容
//空一行
< footer_msg > //footer内容
其中,Header 是必需的,Body 和 Footer 可以省略。
不管是哪一个部分,任何一行都不得超过72个字符(或100个字符)。这是为了避免自动换行影响美观。
type
type用于说明 commit 的类别。
featA new feature
fixA bug fix
docsDocumentation only changes
styleChanges that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
refactorA code change that neither fixes a bug nor adds a feature
perfA code change that improves performance
testAdding missing tests or correcting existing tests
buildChanges that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
ciChanges to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
choreOther changes that don't modify src or test files
revertReverts a previous commit
scope
scope用于说明 commit 影响的范围,比如数据层、控制层、视图层、具体模块等等,视项目不同而不同。
subject
subject是 commit 目的的简短描述,不超过50个字符。
body
Body部分是对本次 commit 的详细描述,可以分成多行。
footer_msg
BREAKING CHANGE,用来描述当前 commit 与上一个版本不兼容的地方。
Issue,用来描述当前 commit 针对的某个issue。
