git flow 流程规范化

git flow 流程

下面是项目里面如何加入git 提交流程规范

1. 安装 commitizen

commitzen约束git commit message 的工具

yarn add commitizen cz-conventional-changelog --dev  

2. 在package.json中加入命令行工具

"scripts": {
    "commit": "git-cz"
},
"config": {
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"
    }
  }

3. 和husky一起约束git commit 在commit时候对于message进行检查

  • 安装commitlint帮助校验message
yarn add @commitlint/config-conventional @commitlint/cli husky --dev   
  • 新建.commitlintrc.js
module.exports = {
  extends: [
    ''@commitlint/config-conventional''
  ],
  rules: {
  }
};
  • 在package.json增加配置husky
 "husky": {
    "hooks": {
      "commit-msg": "commitlint -e $GIT_PARAMS"
    }
  }

4. 测试 git commit

在这里插入图片描述
发现commit msg 没有通过检查

5. 提交时git commit 换为 yarn commit

会出现提示按照提示一步一步写出合乎规范的message
在这里插入图片描述
最后得到的commit message如图格式:
在这里插入图片描述

6. 发布版本自动生成changelog

  • 安装standard-version:自动生成changelog 和 version 的工具
 yarn add standard-version --dev  
  • 加入package script
{
 "script": {
 "release": "standard-version"
 }
  • 新建.versionrc.json文件
{
  "types": [
    {
      "type": "feat",
      "section": "New Features"
    },
    {
      "type": "fix",
      "section": "Bug Fixes"
    },
    {
      "type": "refactor",
      "section": "Refactor"
    },
    {
      "type": "style",
      "section": "Style"
    },
    {
      "type": "docs",
      "section": "Docs"
    },
    {
      "type": "test",
      "section": "Other"
    },
    {
      "type": "build",
      "section": "Other"
    },
    {
      "type": "chore",
      "section": "Other"
    },
    {
      "type": "perf",
      "section": "Other"
    },
    {
      "type": "ci",
      "section": "Other"
    }
  ]
}

  • 最后发布版本的时候
    第一次发布 yarn release --first-release 会过滤掉package.json的version字段不改变, 生成changelog,会打tag
    以后发布 yarn release 会在package.json 的version字段加1 同时改变changelog,会打tag
    这时候会现在一条commit 记录,需要把它和tag一起push上去。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值