Git 提交规范日志
2020-01-21 开发工具
安装 commitizen #
npm install -g commitizen
npm install -g commitizen
项目里运行 使其支持 Angular 的 Commit message 格式
初始化cz包
commitizen init cz-conventional-changelog --save --save-exact
commitizen init cz-conventional-changelog --save --save-exact
以后,凡是用到git commit命令,一律改为使用git cz。这时,就会出现选项,用来生成符合格式的 Commit message。
校验提交 #
validate-commit-msg
用于检查项目的 Commit message 是否符合Angular规范。
npm install --save-dev validate-commit-msg
npm install -D husky
npm install --save-dev validate-commit-msg
npm install -D husky
运行一下命令创建git hooks
npx husky install
npx husky add .husky/pre-commit "npm run test"
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
npx husky install
npx husky add .husky/pre-commit "npm run test"
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
增加提交规则
npm i commitlint -D
npm i commitlint -D
生成 Change log #
- New features
- Bug fixes
- Breaking changes.
npm install -g conventional-changelog-cli
cd my-project
conventional-changelog -p angular -i CHANGELOG.md -w -r 0
npm install -g conventional-changelog-cli
cd my-project
conventional-changelog -p angular -i CHANGELOG.md -w -r 0
git #
git reset --sort HEAD
回退到某一次之前的代码,后面的代码都会拉下来对比
git reset --hard HEAD
回退到某一次之前的提交,后面的代码都丢掉
git revert -n commitId
反悔某一次提交到最前方
git stash
将本地暂存区的保存起来
git stash list
查看缓存的内容
git pop
将暂存的释放出来
package.json
#
{
"name": "commitlint",
"version": "0.1.0",
"private": true,
"dependencies": {},
"scripts": {
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -w -r 0",
"commitmsg": "validate-commit-msg",
"prepare": "husky install"
},
"devDependencies": {
"@commitlint/config-conventional": "^12.1.4",
"commitlint": "^12.1.4",
"cz-conventional-changelog": "^3.3.0"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
{
"name": "commitlint",
"version": "0.1.0",
"private": true,
"dependencies": {},
"scripts": {
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -w -r 0",
"commitmsg": "validate-commit-msg",
"prepare": "husky install"
},
"devDependencies": {
"@commitlint/config-conventional": "^12.1.4",
"commitlint": "^12.1.4",
"cz-conventional-changelog": "^3.3.0"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
[规范验证](
版权属于: vincent
转载时须注明出处及本声明
Tags:# git