【转载】git提交规范

来源:别乱提交代码了,看下大厂 Git 提交规范是怎么做的! - 芋道源码的文章 - 知乎

1.全局安装commitizen & cz-conventional-changelog

npm install -g commitizen cz-conventional-changelog
echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc

安装完毕后,可直接使用git cz来取代git commit。

全局模式下,需要 ~/.czrc 配置文件, 为commitizen指定Adapter。

2. 项目内安装commitlint & husky

commitlint负责用于对commit message进行格式校验,husky负责提供更易用的git hook。

Use npm
npm i -D husky @commitlint/config-conventional @commitlint/cli

Use yarn
yarn add husky @commitlint/config-conventional @commitlint/cli -D

commitlint只能做格式规范,无法触及内容。对于内容质量的把控只能靠我们自己。

3. 添加相应配置

创建commitlint.config.js

# In the same path as package.json

echo 'module.exports = {extends: ["@commitlint/config-conventional"]};' > ./commitlint.config.js

引入husky

# package.json

...,
"husky": {
    "hooks": {
      "commit-msg": "commitlint -e $GIT_PARAMS"
    }
}

使用

执行git cz进入interactive模式,根据提示依次填写

1.Select the type of change that you're committing 选择改动类型 (<type>)

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

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

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

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

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

更多内容,请参考文章开头处*注明来源

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 原文链接 前言 在git的使用中,一种最佳实践是使用格式化的commit信息,这样方便自动化工具进行处理,可以快速...
    冯宇Ops阅读 8,654评论 2 34
  • git commit message格式 git每次提交代码,都必须写commit message(提交说明),用...
    程序_影子阅读 8,615评论 0 4
  • 父亲有两个柜子,一个摆满书,一个堆满酒。 倘若无雨无风,日暮时分的阳光便犹如穿行水中的灵巧锦蛇,转了弯加了速,绕过...
    星期五的方达阅读 1,318评论 4 6
  • 今年的工作在12月17号就结束了,结束得太早,留在德国,可也不庆祝圣诞,有一种毫无节日氛围的闲适感。 许久没飞A3...
    璟小昱阅读 516评论 0 0
  • 目光所及之处皆是回家的路,倒计时 坚持
    868066c96001阅读 106评论 0 1