约定式提交

约定式提交

约定式提交规范是一种基于提交消息的轻量级约定。它提供了一组用于创建清晰的提交历史的简单规则;这使得编写基于规范的自动化工具变得更容易。

feat: allow provided config object to extend other configs

约定式提交的格式


<类型>[可选的作用域]: <描述>

[可选的正文]

[可选的脚注]

Header (<类型>[可选的作用域]: <描述>)  

header包含三部分内容: type(必需),scope(可选)和subject(必需)

type

用于说明commit的类型,常见的类型有:

feat: 新功能
fix: 修补bug
docs: 文档的变更
style: 格式(不影响代码运行的变动)
refactor: 重构(即不是新增功能,也不是修改bug的代码变动)
perf: 用于性能改进的代码提交
test: 用于添加或修改现有测试
build: 修改影响到了系统的构建或外部依赖
ci: 修改CI配置文件或相关的脚本
revert: 用于撤销以前的commit
chore: 其他一些不影响源码或测试文件的代码变动

scope

用于说明commit影响的范围,比如数据层,控制层,视图层等等。

subject

commit目的的简短描述,不超过50个字符。

Body( [可选的正文] )

Body 部分是对本次commit的详细描述,可以分成多行,如

More detailed explanatory text, if necessary. Wrap it to
about 72 characters or so.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Use a hanging indent

填写要求:使用第一人称现在时,比如使用change而不是changed或changes。应该说明代码变动的动机,以及与以前行为的对比。

Footer( [可选的脚注] )

Footer部分只用于两种情况

不兼容变动

如果当前代码与上一个版本不兼容,则Footer部分以BREAKING CHANGE开头,后面是对变动的描述,以及变动理由和迁移方法。如:

BREAKING CHANGE: isolate scope bindings definition has changed.
To migrate the code follow the example below:
    Before:
        scope: {
            myAttr: 'attribute',
        }
    After:
        scope: {
            myAttr: '@',
        }
The removed `inject` wasn't generaly useful for directives so there should be no code using it.

关闭Issue

Closes #234
Closes #123, #245, #992

示例


// 包含了描述以及正文内有破坏性变更的提交说明
feat: allow provided config object to extend other configs
BREAKING CHANGE: `extends` key in config file is now used for extending other config files

// 包含了可选的 ! 字符以提醒注意破坏性变更的提交说明
chore!: drop Node 6 from testing matrix
BREAKING CHANGE: dropping Node 6 which hits end of life in April

// 不包含正文的提交说明
docs: correct spelling of CHANGELOG

// 包含作用域的提交说明
feat(lang): add polish language

// 为 fix 编写的提交说明,包含(可选的) issue 编号
fix: correct minor typos in code
see the issue for details on the typos fixed
closes issue #12

工具


使用commitizen

需提前安装nodejs(官网下载地址)

git cz

安装步骤:

全局安装commitizen node 模块

npm install -g commitizen

在项目目录下运行

npm init --yes
如果是node项目,可直接运行
commitizen init cz-conventional-changelog --save --save-exact

运行完以上步骤就可以使用git cz 替代 git commit 来提交代码,同时会显示选项来自动生成符合格式的commit message.

约定式提交_第1张图片
git cz

git-cz

npm install -g commitizen git-cz

约定式提交_第2张图片
git-cz

使用Git Commit Message Helper

安装方式

idea -> settings -> plugins -> 搜索Git Commit Message Helper

约定式提交_第3张图片
git commit message helper

使用方式

提交时打开idea commit(ctrl+k)

约定式提交_第4张图片

点击上图红框标识部位,会出现如下弹框,之后便可以在该弹框中填写具体的commit信息。

约定式提交_第5张图片
约定式提交_第6张图片

你可能感兴趣的:(约定式提交)