<type>(<scope>) : <subject>
<空行>
<body>
<空行>
<footer>
复制代码
Header部分只有一行,包括三个字段:type
(必需)、scope
(可选)和subject
(必需)git
type
用于说明 commit 的类别,只容许使用下面标识。npm
若是 type
为 feat
和 fix
,则该 commit 将确定出如今 Change log 之中。json
scope
用于说明 commit 影响的范围,好比数据层、控制层、视图层等等,视项目不一样而不一样。bash
subject
是 commit 目的的简短描述,不超过50个字符。工具
Body 部分是对本次 commit 的详细描述,能够分红多行。下面是一个范例。性能
More detailed explanatory text, if necessary. Wrap it to
about 72 characters or so.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Use a hanging indent
复制代码
Footer 部分只用于两种状况。单元测试
不兼容变更测试
若是当前代码与上一个版本不兼容,则 Footer 部分以 BREAKING CHANGE
开头,后面是对变更的描述、以及变更理由和迁移方法。优化
BREAKING CHANGE: isolate scope bindings definition has changed.
To migrate the code follow the example below:
Before:
scope: {
myAttr: 'attribute',
}
After:
scope: {
myAttr: '@',
}
The removed `inject` wasn't generaly useful for directives so there should be no code using it. 复制代码
关闭 Issueui
若是当前 commit 针对某个issue,那么能够在 Footer 部分关闭这个 issue 。
Closes #234
复制代码
也能够一次关闭多个 issue 。
Closes #123, #245, #992
复制代码
安装
$ npm install -g commitizen
复制代码
在项目目录里运行下面命令
$ commitizen init cz-conventional-changelog --save --save-exact
复制代码
之后,凡是用到git commit命令,一概改成使用git cz。这时,就会出现选项,用来生成符合格式的 Commit message。
安装
$ npm i @commitlint/cli @commitlint/config-conventional husky -D
复制代码
配置 commitlint.config.js 在项目根目录下新建 commitlint.config.js
, 内容以下:
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'subject-case': [0, 'never'],
'type-enum': [
2,
'always',
[
"docs", // Adds or alters documentation. 仅仅修改了文档,好比README, CHANGELOG, CONTRIBUTE等等
"chore", // Other changes that don't modify src or test files. 改变构建流程、或者增长依赖库、工具等 "feat", // Adds a new feature. 新增feature "fix", // Solves a bug. 修复bug "merge", // Merge branch ? of ?. "perf", // Improves performance. 优化相关,好比提高性能、体验 "refactor", // Rewrites code without feature, performance or bug changes. 代码重构,没有加新功能或者修复bug "revert", // Reverts a previous commit. 回滚到上一个版本 "style", // Improves formatting, white-space. 仅仅修改了空格、格式缩进、逗号等等,不改变代码逻辑 "test", // Adds or modifies tests. 测试用例,包括单元测试、集成测试等 "build" // 构建 ] ] } }; 复制代码
修改package.json 文件夹
在package.json 中添加husky 配置
...
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
...
复制代码
conventional-changelog
就是生成 Change log 的工具,运行下面的命令便可。
$ npm install -g conventional-changelog-cli
$ cd my-project
$ conventional-changelog -p angular -i CHANGELOG.md -w
复制代码
上面命令不会覆盖之前的 Change log,只会在 CHANGELOG.md
的头部加上自从上次发布以来的变更。
若是你想生成全部发布的 Change log,要改成运行下面的命令。
$ conventional-changelog -p angular -i CHANGELOG.md -w -r 0
复制代码
为了方便使用,能够将其写入package.json的scripts字段。
{
"scripts": {
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -w -r 0"
}
}
复制代码
之后,直接运行下面的命令便可。
$ npm run changelog
复制代码