·vincent
Git 提交规范日志
Git 提交规范日志
git
安装 commitizen
bash
1npm install -g commitizen
项目里运行 使其支持 Angular 的 Commit message 格式
初始化cz包
bash
1commitizen init cz-conventional-changelog --save --save-exact
以后,凡是用到git commit命令,一律改为使用git cz。这时,就会出现选项,用来生成符合格式的 Commit message。
校验提交
validate-commit-msg
用于检查项目的 Commit message 是否符合Angular规范。
bash
1npm install --save-dev validate-commit-msg
2npm install -D husky
运行一下命令创建git hooks
bash
1npx husky install
2npx husky add .husky/pre-commit "npm run test"
3npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
增加提交规则
bash
1npm i commitlint -D
生成 Change log
- New features
- Bug fixes
- Breaking changes.
bash
1npm install -g conventional-changelog-cli
2cd my-project
3conventional-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
json
1{
2 "name": "commitlint",
3 "version": "0.1.0",
4 "private": true,
5 "dependencies": {},
6 "scripts": {
7 "changelog": "conventional-changelog -p angular -i CHANGELOG.md -w -r 0",
8 "commitmsg": "validate-commit-msg",
9 "prepare": "husky install"
10 },
11 "devDependencies": {
12 "@commitlint/config-conventional": "^12.1.4",
13 "commitlint": "^12.1.4",
14 "cz-conventional-changelog": "^3.3.0"
15 },
16 "config": {
17 "commitizen": {
18 "path": "./node_modules/cz-conventional-changelog"
19 }
20 }
21}
[规范验证](