git commit相关工具

配置检查脚本

公共也有很多其他检查脚本,公司使用自己写的一个检查脚本,将其防止在项目目录.git/hooks中即可,保密原因不进行展示

配置commitizen,changelog

# npm命令依赖node.js实现需要先安装好
# 1.安装commitizen cz-conventional-changelog conventional-changelog-cli
npm install commitizen cz-conventional-changelog conventional-changelog-cli --save-dev
# 2.修改cz-conventional-changelog中engine.js源码使之符合公司规范
# file path:项目根目录\node_modules\commitizen\node_modules\cz-conventional-changelog\engine.js
# 修改24行 filterSubject方法:注释subject首字母自动小写逻辑
  // if (subject.charAt(0).toLowerCase() !== subject.charAt(0)) {
  //   subject =
  //     subject.charAt(0).toLowerCase() + subject.slice(1, subject.length);
  // }
# 修改203行 head变量默认值,在subject默认加上[cr_id_skip],使subject每次自动加上,符合commit-msg验证标准
var head = answers.type + scope + ': [cr_id_skip] ' + answers.subject;
# 3.修改conventional-changelog-angular源码,使之自动生成CHANGELOG.md(可选操作,推荐)
# file path:项目根目录\node_modules\cz-conventional-changelog-angular\writer-opts.js
# 修改28行 discard变量,默认置为false
      let discard = false
# 注释31~34行
      // commit.notes.forEach(note => {
      //   note.title = 'BREAKING CHANGES'
      //   discard = false
      // })
# 原commit.type相关if逻辑判断替换如下:
      if (commit.type === 'feat') {
        commit.type = '✨ Features | 新功能'
      } else if (commit.type === 'fix') {
        commit.type = '🐛 Bug Fixes | Bug 修复'
      } else if (commit.type === 'perf') {
        commit.type = '⚡ Performance Improvements | 性能优化'
      } else if (commit.type === 'revert' || commit.revert) {
        commit.type = '⏪ Reverts | 回退'
      } else if (discard) {
        return
      } else if (commit.type === 'docs') {
        commit.type = '📝 Documentation | 文档'
      } else if (commit.type === 'style') {
        commit.type = '💄 Styles | 风格'
      } else if (commit.type === 'refactor') {
        commit.type = '♻ Code Refactoring | 代码重构'
      } else if (commit.type === 'test') {
        commit.type = '✅ Tests | 测试'
      } else if (commit.type === 'build') {
        commit.type = '👷‍ Build System | 构建'
      } else if (commit.type === 'ci') {
        commit.type = '🔧 Continuous Integration | CI 配置'
      } else if (commit.type === 'chore') {
        commit.type = '🎫 Chores | 其他更新'
      }

Tips: 记得把项目中node_modules目录添加之.gitgnore中,避免push到远程仓库

在这里插入图片描述

可通过修改目录中package.json,通过npm对git相关操作进行命令融合

{
  "devDependencies": {
    "commitizen": "^4.2.4",
    "conventional-changelog-cli": "^2.1.1",
    "cz-conventional-changelog": "^3.3.0"
  },
  "scripts": {
    "commit": "git add . && git-cz && arc diff ",
    "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
    "push": "git push origin feature-AIDI-Data && npm run changelog"
  },
  "config": {
    "commitizen": {
      "path": "cz-conventional-changelog"
    }
  }
}

Tips: push中可替换需要提交的对应分支,公司有代码走查所以有个arc diff
融合后命令操作: npm run commit → npm run push

  • npm run commit(自动顺序执行git add . → git-cz → arc diff)

1.添加修改文件

2.进入交互页面

2.1.选择修改类型,自动化一般就选test,回车进入下一步
在这里插入图片描述
2.2.选择改动范围,根据公司规范可使用模块名、文件名、文件夹名,级别自定,多个使用逗号分隔,没有可以直接回车跳过,回车进入下一步
在这里插入图片描述
2.3.填写header注意字符计数不要超过72,使用英文描述,开头字母大写,回车进入下一步
在这里插入图片描述
2.4.填写详细描述,可使用中文和中文符号,一行不要超过72字符,输入\n代表换行,回车进入下一步
在这里插入图片描述
2.5.最后2步直接输入n跳过
在这里插入图片描述
2.6.完成后将显示完整header,body不会显示,使用git show可以看到详细
在这里插入图片描述
在这里插入图片描述

  • npm run commit(自动顺序执行git push origin 【branch name】→ npm run changelog)
    Arc diff和push后body会附加到summary上
    在这里插入图片描述

自动生成CHANGELOG.md
符合标准的commit会自动生成title及emoji
在这里插入图片描述

最后特别感觉:https://blog.cmyr.ltd/archives/caf24092.html这篇博文,使我找到了实现方向

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值