npm install commitizen -g
// 安装 conventional-changelog 格式 (全局)
npm install cz-conventional-changelog -g
// 配置格式
echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc
// 缺点:必须使用 node npm 以及项目中添加依赖
// 如果没有 pcakge.json 或项目中没有使用 先初始化
npm init --yes
// 用 commitizen 设置依赖并初始化
commitizen init cz-conventional-changelog --save-dev --save-exact
// 首先必须已全局安装 commitizen
// 成员只需安装依赖就可以了
npm install
// 使用下面命令以代替 git commit
git cz
validate-commit-msg 用于检查 Node 项目的 Commit message 是否符合格式。
它的安装是手动的。首先,拷贝下面这个JS文件,放入你的代码库。文件名可以取为validate-commit-msg.js。 接着,把这个脚本加入 Git 的 hook。下面是在package.json里面使用 ghooks,把这个脚本加为
commit-msg
时运行。
"config": {
"ghooks": {
"commit-msg": "./validate-commit-msg.js"
}
}
然后,每次git commit的时候,这个脚本就会自动检查 Commit message 是否合格。如果不合格,就会报错。
git add -A
git commit -m "edit markdown"
INVALID COMMIT MSG: does not match "<type>(<scope>): <subject>" ! was: edit markdown
包含三个部分
* New features
* Bug fixes
* Breaking changes.
npm install -g conventional-changelog
cd my-project
conventional-changelog -p angular -i CHANGELOG.md -w // 上次发布以来的变动
conventional-changelog -p angular -i CHANGELOG.md -w -r 0 // 所有发布
-
将命令加入到 package.json 的
scripts
scope 中 -
例如
{ "scripts": { "changelog": "conventional-changelog -p angular -i CHANGELOG.md -w", "changelog-all": "conventional-changelog -p angular -i CHANGELOG.md -w -r 0" } }
-
之后即可运行
npm run changelog
-
还可将
npm run changelog
加入到构建中,每次提交构建自动生成