Git Commitizen 规范化commit工具

一、安装 Commitizen 工具

需要提前安装node。

1. 安装 commitizen node 模块

npm install -g commitizen

2. 初始化 commitizen 的适配器 cz-customizable

npm install -g cz-customizable

3. 安装生成log日志的模块

npm install -g conventional-changelog-cli

报错可以重新执行命令尝试一下

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
npm ERR! code ECONNRESET
npm ERR! network aborted
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network 
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/tao/.npm/_logs/2021-01-23T10_12_59_442Z-debug.log

二、使用

1. 生成 package.json

# cd 到项目目录,执行命令
$ npm init
#然后根据提示填写相关的项目信息
#完成后会生成package.json

2. 在 package.json中添加脚本

在 scripts中添加:

$ "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s 0"
1
2
3
4
5
	#不会覆盖以前的 Change log,只会在 CHANGELOG.md 的头部加上自从上次发布以来的变动
	$ conventional-changelog -p angular -i CHANGELOG.md -s
 
	# 生成所有发布的 Change log,会覆盖以前的 Change log
	$ conventional-changelog -p angular -i CHANGELOG.md -w -r -s 0

示例如下:

1
2
3
4
"scripts": {
   "test": "echo \"Error: no test specified\" && exit 1",
   "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s 0"
 },

这个脚本可以在通过在终端输入 npm run changelog 生成 CHANGELOG.md 日志文档。

2. 加载node_modules依赖组件 (cz)

$ commitizen init cz-conventional-changelog —save —save-exact

执行完以后,项目中就可以一律使用 git cz 代替 git commit来提交代码。

同时会显示type选项来自动生成符合格式的 commit message。

三、代码提交

  • git add .
  • git cz //使用 git cz 代替之前的 git commit

代码提交流程

1.Select the type of change that you’re committing 选择改动类型

2.What is the scope of this change (e.g. component or file name)? 填写改动范围

3.Write a short, imperative tense description of the change: 写一个精简的描述

4.Provide a longer description of the change: (press enter to skip) 对于改动写一段长描述

5.Are there any breaking changes? (y/n) 是破坏性修改吗?默认n

6.Does this change affect any openreve issues? (y/n) 改动修复了哪个问题?默认n


类型说明

  • feat: A new feature
  • fix: A bug fix
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi- colons, etc)
  • refactor: A code change that neither fixes a bug nor adds a feature
  • perf: A code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies (example scopes: gulp, brocc oli, npm)
  • ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, Browser Stack, SauceLabs)
  • chore: Other changes that don’t modify src or test files
  • revert: Reverts a previous commit

四、Jira

设置gitlab Network配置

图片

进入要配置的项目,点击设置。(这里和上面那个设置不同,这里是设置项目里的配置)

往下滑动一点儿,有个保存。保存。保存。不要忘记保存。

配置 Jira

图片

Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy