美文网首页
使用 commitizen 优化 git 提交

使用 commitizen 优化 git 提交

作者: 许盛 | 来源:发表于2020-04-10 13:13 被阅读0次

之前写了一篇博客,用来做备忘,每次有新项目的时候,就上去复制粘贴:

关于项目 git 协作流程的思考

但是因为有一些思考过程,所以不太方便施展 C+V 大法,现在汇总一下。

一、安装依赖

yarn add -D commitizen \
  cz-conventional-changelog \
  @commitlint/config-conventional \
  @commitlint/cli \
  husky \
  standard-version

二、添加配置文件

在项目根目录下,添加 .commitlintrc.js 文件。

.commitlintrc.js

内容如下:

module.exports = {
  extends: [
    '@commitlint/config-conventional'
  ],
  rules: {
  }
};

三、修改 package.json 文件

// 修改 scripts 部分
scripts: {
    "commit": "git-cz",
    "release": "standard-version"
}

// 修改或添加 config 字段
"config": {
    "commitizen": {
        "path": "node_modules/cz-conventional-changelog"
    }
}

// 修改或添加 kusky 字段
"husky": {
    "hooks": {
      "commit-msg": "commitlint -e $GIT_PARAMS"
    }
  },

四、总结

这个时候,运行 yarn commit 命令就可以提交代码.

1. 自动 release

运行 yarn release 命令就可以用来自动更新 package.json 中的 version 字段,生成或更新 CHANGELOG.md 文件,以及触发一次 release 提交并打上相应的 git tag

2. 修改 CHANGELOG.md 生成规则

如果想对生成的 CHANGELOG.md 自定义规则的话,可以参考:Conventional Changelog Configuration Spec (v2.1.0)

3. 第一次 release

第一次调用 yarn release 命令的话,加上 --first-release 参数,这样就不会自动修改当前 package.json 的版本号了。

4. 手动指定版本号

需要手动指定版本号的话,使用 --release-as <版本号> 参数。

5. 指定 git tag 的前缀

standard version 默认会在版本号之前加上 v 的前缀。

比如执行 standard version --release-as 1.1.0 命令,会发现分支被打上了 v1.1.0 标签。

如果想要指定前缀的话,可以使用 -t [前缀] 参数。

If you do not want to have any tag prefix you can use the -t flag without value.

官网上说的是如果不希望加前缀的话,-t 参数的值不给就行,但是我直接测试了一下,如果 -t 的值不给的话,还是加上的 v 前缀,必须得指定为空字符串 '' 才行。

相关文章

  • 使用 commitizen 优化 git 提交

    之前写了一篇博客,用来做备忘,每次有新项目的时候,就上去复制粘贴: 关于项目 git 协作流程的思考 但是因为有一...

  • Git学习笔记-多人协作

    多人协作使用Git的基本约定 一. 按规定格式提交 commit message 使用 commitizen 等工...

  • Git 提交规范(commitizen 使用流程)

    全局安装 commitizen 对代码修改后,使用 git add 将修改文件存入暂存区 使用 git cz 此时...

  • git日志提交规范

    安装日志提交工具 https://github.com/commitizen/cz-cli[https://git...

  • git commit 规范

    使用angular + commitizen + cz-conventional-changelog 来规范git...

  • 规范git 提交

    使用 commitizen包来管理提交 安装pkg 添加配置 配置脚本

  • commitizen提交规范以及git语法

    commitizen是git提交信息的一种消息模式安装方法是: 然后,在项目目录里,运行下面的命令,使其支持Com...

  • commitizen全家桶

    commitizen全家桶 标准化的git commig帮助你实现自动化changelog commitizen ...

  • git commitizen

    AngularJS团队提交规范 全局安装完成后在使用git commit代码时使用git cz 代替 后按提示填写即可

  • Git使用记录

    本地Git撤回提交记录 使用git log查看提交的历史记录 使用git reset --soft head~1撤...

网友评论

      本文标题:使用 commitizen 优化 git 提交

      本文链接:https://www.haomeiwen.com/subject/hscrmhtx.html