git cz安装和使用
文章目录
1. cz简介
Commitizen:https://github.com/commitizen/cz-cli 当您使用commtizen提交时,将提示您在提交时填写所有必需的提交字段。
简单来说就是一个规范化的提交git message的插件工具:
安装之后可以规范化提交,便于管理git提交的内容,配合changelog插件可以命令话生成CHANGELOG.md,不用再单独写版本说明文档了。
2. Windows下安装和使用
2.1 需要先安装Node.js和npm
官网下载Node.js(https://nodejs.org/),选择Windows平台下的LTS版本:https://nodejs.org/dist/v14.17.4/node-v14.17.4-x64.msi
下载好后像按照普通软件一样安装即可,目前版本会自动添加到环境变量,如果没有加进去的话手动添加安装目录到环境变量Path即可:
然后在终端查看node.js版本和npm(npm即Node.js的包管理工具,和python的包管理工具pip类似,安装语言时一般会预装)版本即可:
PS C:\Users\admin> node -v
v14.17.4
PS C:\Users\admin> npm -v
6.14.14
2.2 安装commitizen及使用
# 安装commitzen
npm install commitizen -g
# 使用:使用git cz替代之前的git commit即可
git add .
git cz
执行git cz后会出现选项进行选择,Windows下使用powershell或者cmd,使用git bash会无法选择选项。
> git cz
cz-cli@4.2.4, cz-conventional-changelog@3.2.0
? Select the type of change that you're committing: feat: A new feature
? What is the scope of this change (e.g. component or file name): (press enter to skip) 测试
? Write a short, imperative tense description of the change (max 90 chars):
(4) 测试提交
? Provide a longer description of the change: (press enter to skip)
测试一下如何使用cz提交
? Are there any breaking changes? Yes
? Describe the breaking changes:
学会用cz了,真不错
? Does this change affect any open issues? No
[master (root-commit) 602c8f4] feat(测试): 测试提交
3 files changed, 384 insertions(+)
type说明:
feat:新功能(feature)
fix:修补bug
docs:文档(documentation)
style: 格式(不影响代码运行的变动)
refactor:重构(即不是新增功能,也不是修改bug的代码变动)
test:增加测试
chore:构建过程或辅助工具的变动
2.3 安装changelog及使用
# 安装changelog
npm install -g conventional-changelog
# 进入项目目录
cd my-project
# 根据提交记录胜场CHANGE.md,在里面就有各个版本的信息,这样就不用再单独添加版本说明了
conventional-changelog -p angular -i CHANGELOG.md -w
# 生成文件
conventional-changelog.cmd -p angular -i CHANGELOGTEST.md -s
2.4 添加node脚本
我们将上面生成文件的命令写到脚本中,方便生成文件,既然已经安装了Node.js,那么利用Node的特性生成package.json后添加脚本命令即可:
# 在项目目录下执行:
npm init
输入相关内容后生成package.json,然后修改内容,在scripts下添加对应命令即可:
{
"name": "devctl_client",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
},
"author": "",
"license": "ISC"
}
这样在当前目录下执行:
npm run changelog
就可以生成对应的CHANGELOG了。
参考:
https://www.jianshu.com/p/201bd81e7dc9?utm_source=oschina-app
http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html