Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1️⃣ GIT message 规范 #77

Open
Genluo opened this issue Dec 19, 2019 · 1 comment
Open

1️⃣ GIT message 规范 #77

Genluo opened this issue Dec 19, 2019 · 1 comment
Assignees
Labels

Comments

@Genluo
Copy link
Owner

Genluo commented Dec 19, 2019

git message规范整理

Commit Message规范

<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
  • 标题行: 必填, 描述主要修改类型和内容
  • 主题内容: 描述为什么修改, 做了什么样的修改, 以及开发的思路等等
  • 页脚注释: 放 Breaking Changes 或 Closed Issues

1. 标题行

type的类型为:

  • feat: 新特性
  • fix: 修改问题
  • refactor: 代码重构
  • docs: 文档修改
  • style: 代码格式修改, 注意不是 css 修改
  • test: 测试用例修改
  • chore: 其他修改, 比如构建流程, 依赖管理
  • scope: commit 影响的范围, 比如: route, component, utils, build...
  • subject: commit 的概述, 建议符合 50/72 formatting

2. 主题内容

描述为什么修改,做了什么样的修改,以及开发思路相关

3. 页脚注释

一些备注, 通常是 BREAKING CHANGE 或修复的 bug 的链接

4. 实例

实例

规范化

1. 设置git commit 模板

通过 git commit 进入多行编辑模式

  • 修改 ~/.gitconfig, 添加:
[commit]
template = ~/.gitmessage
  • 编写 .gitmessage 文件,内容如下:
# head: <type>(<scope>): <subject>
# - type: feat, fix, docs, style, refactor, test, chore
# - scope: can be empty (eg. if the change is a global or difficult to assign to a single component)
# - subject: start with verb (such as 'change'), 50-character line
#
# body: 72-character wrapped. This should answer:
# * Why was this change necessary?
# * How does it address the problem?
# * Are there any side effects?
#
# footer: 
# - Include a link to the ticket, if any.
# - BREAKING CHANGE
#
  • 或者使用
git config --global commit.template ~/.gitmessage

2. 使用工具进行规范化提交

安装步骤:

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

使用:

git cz

详情参见: https://juejin.im/post/5afc5242f265da0b7f44bee4

3. 配置强制进行检查,不通过,不予提交

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

  • 写commitlint的配置文件

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

  • 在package.json 中配置bin命令,然后执行npm link
  "bin": {
       "commitlint": "./node_modules/@commitlint/cli/lib/cli.js"
  }

npm install husky --save-dev

  • 配置hooks,commit 钩子,在package.json 中加入如下内容
{
  "husky": {
    "hooks": {
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }  
  }
}
  • 进行提交测试

参考文档

@Genluo Genluo added the 通用 label Dec 19, 2019
@Genluo Genluo self-assigned this Dec 19, 2019
@Genluo Genluo pinned this issue Dec 19, 2019
@Genluo Genluo changed the title GIT message 规范 1️⃣ GIT message 规范 Dec 19, 2019
@Genluo
Copy link
Owner Author

Genluo commented Dec 30, 2019

配置全局.gitignore文件
issue地址:alibaba/rax#1633

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant