git Commitizen工具安装使用
Commitizen工具安装使用
npm install -g commitizen
commitizen init cz-conventional-changelog --save --save-exact //在项目目录下执行
//提交代码
git add .
git cz //所有的git commit 都用git cz替换
安装validate-commit-msg校验
// 安装 validate-commit-msg
npm install --save-dev validate-commit-msg
// 安装 ghooks
cnpm install ghooks --save-dev
// 在 package.json 配置 ghooks
"config": {
"ghooks": {
"commit-msg": "validate-commit-msg"
},
"validate-commit-msg": {
"types": ["feat", "fix", "docs", "style", "refactor", "perf", "test", "build", "ci", "chore", "revert"],
"scope": {
"required": false,
"allowed": ["*"],
"validate": false,
"multiple": false
},
"warnOnFail": false,
"maxSubjectLength": 100,
"subjectPattern": ".+",
"subjectPatternErrorMsg": "subject does not match subject pattern!",
"helpMessage": "",
"autoFix": false
}
}
说明:如果修改文件 再次写 git commit -m “***”,会报错
Changelog使用
// 安装 changelog
sudo cnpm install -g conventional-changelog
或者安装changlog-cli
npm install -g conventional-changelog-cli
// 在 package.json 的 scripts 字段写入
"scripts": {
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -w -r 0"
}
// 生成CHANGELOG文件
conventional-changelog -p angular -i CHANGELOG.md -s
// 生成CHANGLOG日志
npm run changelog
完整的package.json文件内容如下:
{
"devDependencies": {
"ghooks": "^2.0.4"
},
"config": {
"ghooks": {
"commit-msg": "validate-commit-msg"
},
"validate-commit-msg": {
"types": ["feat", "fix", "docs", "style", "refactor", "perf", "test", "build", "ci", "chore", "revert"],
"scope": {
"required": false,
"allowed": ["*"],
"validate": false,
"multiple": false
},
"warnOnFail": false,
"maxSubjectLength": 100,
"subjectPattern": ".+",
"subjectPatternErrorMsg": "subject does not match subject pattern!",
"helpMessage": "",
"autoFix": false
}
},
"scripts": {
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -w -r 0"
}
}
相关连接
https://juejin.cn/post/6844903897622904845
https://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html
【励志篇】:
古之成大事掌大学问者,不惟有超世之才,亦必有坚韧不拔之志。