docs(message): add

This commit is contained in:
zjkjzj
2021-03-18 15:25:47 +08:00
parent 272f8b62cd
commit f573027057
8 changed files with 548 additions and 10 deletions

View File

@@ -1,16 +1,16 @@
# GitGuide
* 规范
* README编写
* `GIT`工作流
* `README`编写
* 消息提交
* 版本提交
* GIT工作流
* 工具
* Git
* Commitizen
* conventioanl-changelog
* CommitLint+Husky
* generator-standard-readme
* `Git`
* `Commitizen`
* `conventioanl-changelog`
* `CommitLint+Husky`
* `generator-standard-readme`
* 平台
* GitLab
* GitHub
* `GitLab`
* `GitHub`

View File

@@ -0,0 +1,102 @@
# Angular提交规范
目前最受开发人员肯定的规范是前端框架`Angular`提出的[Angular提交信息规范](https://github.com/angular/angular/blob/22b96b9/CONTRIBUTING.md#-commit-message-guidelines)
提交格式如下:
<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
每次提交可以包含页眉(`header`)、正文(`body`)和页脚(`footer`),每次提交**必须包含页眉内容**
每次提交的信息不超过`100`个字符
详细文档:[AngularJS Git Commit Message Conventions](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit#)
## 页眉设置
页眉的格式指定为提交类型(`type`)、作用域(`scope`,可选)和主题(`subject`)
### 提交类型
提交类型指定为下面其中一个:
1. `build`:对构建系统或者外部依赖项进行了修改
2. `ci`对CI配置文件或脚本进行了修改
3. `docs`:对文档进行了修改
4. `feat`:增加新的特征
5. `fix`:修复`bug`
6. `pref`:提高性能的代码更改
7. `refactor`:既不是修复`bug`也不是添加特征的代码重构
8. `style`:不影响代码含义的修改,比如空格、格式化、缺失的分号等
9. `test`:增加确实的测试或者矫正已存在的测试
### 作用域
范围可以是任何指定提交更改位置的内容
### 主题
主题包括了对本次修改的简洁描述,有以下准则
1. 使用命令式,现在时态:“改变”不是“已改变”也不是“改变了”
2. 不要大写首字母
3. 不在末尾添加句号
## 正文设置
和主题设置类似,使用命令式、现在时态
应该包含修改的动机以及和之前行为的对比
## 页脚设置
### Breaking changes
不兼容修改指的是本次提交修改了不兼容之前版本的`API`或者环境变量
所有不兼容修改都必须在页脚中作为中断更改块提到,以`BREAKING CHANGE`:开头,后跟一个空格或者两个换行符,其余的信息就是对此次修改的描述,修改的理由和修改注释
BREAKING CHANGE: isolate scope bindings definition has changed and
the inject option for the directive controller injection was removed.
To migrate the code follow the example below:
Before:
。。。
。。。
After:
。。。
。。。
The removed `inject` wasn't generaly useful for directives so there should be no code using it.
### 引用提交的问题
如果本次提交目的是修改`issue`的话,需要在页脚引用该`issue`
以关键字`Closes`开头,比如
Closes #234
如果修改了多个`bug`,以逗号隔开
Closes #123, #245, #992
## 回滚设置
当此次提交包含回滚(`revert`)操作,那么页眉以`"revert:"`开头,同时在正文中添加`"This reverts commit hash"`,其中`hash`值表示被回滚前的提交
revert:<type>(<scope>): <subject>
<BLANK LINE>
This reverts commit hash
<other-body>
<BLANK LINE>
<footer>

View File

@@ -0,0 +1,123 @@
# Conventional提交规范
[Conventional Commits](https://www.conventionalcommits.org)(约定式提交)脱胎于`Angular`提交信息准则,提供了更加通用、简洁和灵活的提交规范
提交格式如下:
<类型>[可选的作用域]: <描述>
# 空一行
[可选的正文]
# 空一行
[可选的脚注]
## 页眉设置
强制支持的类型名是`fix``feat`,同样支持`Angular`准则中推荐的其他类型
常规提交规范还推荐使用类型`improvement`,表示在不添加新功能或修复`bug`的情况下改进当前的实现
## 页尾设置
强制支持在页脚使用`BREAKING CHANGES`
## 提交规范
结合[RFC2019](https://www.ietf.org/rfc/rfc2119.txt),在下面规范中使用关键字来指示需求级别
* `MUST`(必须)
* `MUST NOT`(禁止)
* `REQUIRED`(需要)
* `SHALL`(应当)
* `SHALL NOT`(不应当)
* `SHOULD`(应该)
* `SHOULD NOT`(不应该)
* `RECOMMENDED`(推荐)
* `MAY`(可以)
* `OPTIONAL`(可选)
1. 每次提交**必须**添加类型名为前缀。类型名是一个名词,比如`feat、fix`,后跟冒号和一个空格
2. 类型`feat`**必须**在提交新特征时使用
3. 类型`fix`**必须**用于修复`bug`的提交
4. 类型后面**可以**添加一个可选的作用域。作用域名是一个短语,表示代码库中的一个小节,比如`fix(parser)`
5. 在类型/作用域前缀后面**必须**跟上一个简短描述,关于本次提交的代码修改,比如`fix: 字符串中包含多个空格时的数组分析问题`
6. **可以**在描述后面添加一个长的正文,用于提供额外的上下文信息。正文内容**必须**在短描述后空一行开始
7. **可以**在正文后空一行开始页脚,页脚**应该**包含这次代码修改的相关问题,比如`Fixes #13`
8. 不兼容修改(`breaking change`)**必须**放置在提交的页脚或正文部分的最开始处,**必须**使用大写文本`BREAKING CHANGE`作为前缀,后跟冒号和一个空格
9.`BREAKING CHANGE:`后面**必须**提供一个描述,关于`API`的修改,比如`BREAKING CHANGE: 环境变量目前优先于配置文件`
10. 页脚**必须**包含不兼容修改、额外链接、问题引用和其他元信息
11. 除了`feat``fix`以外的类型**可以**在提交信息中使用
## 徽章
使用了常规提交规范可以添加徽章在`README`
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
## 实现示例
只有页眉和页尾
feat: allow provided config object to extend other configs
BREAKING CHANGE: `extends` key in config file is now used for extending other config files
只有页眉
docs: correct spelling of CHANGELOG
使用了作用域
feat(lang): added polish language
修复了`bug`
fix: minor typos in code
see the issue for details on the typos fixed
fixes issue #12
## `FAQ`
问:在最初开发阶段如何处理提交信息?
建议像已发布产品一样处理。即使是你的软件开发伙伴在使用软件过程中,也想知道那些被修复了,那些是不兼容修改。
问:提交头的类型名是大写还是小写?
无所谓,不过最好保持一致(一直大写或一直小写)
**问:如果提交内容适用于多个类型怎么办?**
尽可能返回并进行多次提交。常规提交准则的优势在于它有能力驱动我们进行更加组织化的提交和`PR`
问:这是否是不鼓励快速开发和快速迭代?
它不鼓励以无序的方式快速开发。它帮助你在有多个开发者的多个项目中进行长期开发
**问:常规提交准则是否会限制提交的类型?**
常规提交准则鼓励开发者使用更多有确切含义的类型。除此以外,准则的灵活性允许开发组提出更多适用于自己的类型,并随着时间的推移更改这些类型
问:这个准则和[SemVer](https://semver.org/lang/zh-CN/)的联系?
`fix`类型应该翻译成`PATCH`版本。`feat`类型应该翻译成`MINOR`版本。如果提交信息中包含`不兼容修改`,不管哪种类型,都应该翻译成`MAJOR`版本
问:如何将扩展版本转换为常规提交规范?
我们建议使用`SemVer`发布您自己对本规范的扩展(并鼓励您进行这些扩展!)
**问:如果我不小心使用了错误的提交类型,该怎么办?**
1. 使用了规范中的类型但是没有使用正确的类型,比如使用`fix`替代了`feat`
在合并或者发布这个错误之前,推荐使用`git rebase -i`进行提交历史编辑。发布之后,依据使用的工具或流程进行清理
2. 当使用了规范外的类型,比如使用了`feet`替代了`feat`
如果提交不符合常规提交规范,它只是意味着基于规范的工具将错过这次提交
**问:是否我的所有贡献者都需要使用常规提交规范?**
如果使用基于`squash``Git`工作流,主管维护者可以在合并时清理提交信息——这不会对普通提交者产生额外的负担。常见的工作流程是让`git`系统自动从`pull request``squash`出提交,并向主维护者提供一份表单,用以在合并时输入适合的`git`提交信息。

View File

@@ -0,0 +1,83 @@
# [gitmessage]提交模板
## 默认模板
在提交时打开编译器,默认会出现一段模板信息,提示你编辑提交信息,同时会提示当前修改的文件
$ git commit
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
# (use "git push" to publish your local commits)
#
# Changes to be committed:
# modified: ...
# deleted: ...
#
## 自定义模板
可以自己编辑一个模板文件,比如新建`~/.gitmessage`,编辑一段关于提交规范的注释
$ vim ~/.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
#
修改全局配置文件`~/.gitconfig`,添加
[commit]
template = ~/.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
#
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Your branch is ahead of 'all/master' by 2 commits.
# (use "git push" to publish your local commits)
#
# Changes to be committed:
# new file: .gitignore
#
# Untracked files:
# package.json
#
## 文件解析
在仓库内的`.git/COMMIT_EDITMSG`文件中保存了最近一次提交的日志(包括模板信息)
## 相关阅读
* [优雅的提交你的 Git Commit Message](https://zhuanlan.zhihu.com/p/34223150)

15
docs/message/index.md Normal file
View File

@@ -0,0 +1,15 @@
# 引言
每次进行`git`提交时,需要写提交说明,规范提交说明的好处如下
1. 更加结构化的提交历史
2. 保证每次信息都有确切的含义
3. 方便直接生成`changelog`
4. 方便信息搜索和过滤
## 相关阅读
* [Commit message 和 Change log 编写指南](http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html)
* [如何写好 Git commit log?](https://www.zhihu.com/question/21209619)
* [优雅的提交你的 Git Commit Message](https://zhuanlan.zhihu.com/p/34223150)

View File

@@ -0,0 +1,125 @@
# [CommitLint][Husky]消息校验工具
参考:[commitlint](https://conventional-changelog.github.io/commitlint/#/)
使用`commitizen`可以规范化提交信息,同样的,可以设置工具来检查提交信息是否符合格式要求
* [commitlint](https://github.com/conventional-changelog/commitlint):用于检查提交信息
* [husky](https://github.com/typicode/husky)是`hook`工具,作用于`git-commit``git-push`阶段
使用场景:
1. 本地信息检查
2. `CI`信息检查
## `commitlint`
### 全局安装
$ npm install -g @commitlint/cli @commitlint/config-conventional
### 本地安装
$ npm install --save-dev @commitlint/{cli,config-conventional}
### 配置规范
# 使用conventional规范
$ echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js
### 测试
需要全局安装才能在命令行使用`commitlint`
# 错误示例,类型后跟一个冒号和一个空格
$ echo "docs:添加新的文档" | commitlint
⧗ input: docs:添加新的文档
✖ subject may not be empty [subject-empty]
✖ type may not be empty [type-empty]
✖ found 2 problems, 0 warnings
(Need help? -> https://github.com/conventional-changelog/commitlint#what-is-commitlint )
# 正确示例
$ echo "docs: 添加新的文档" | commitlint
⧗ input: docs: 添加新的文档
✔ found 0 problems, 0 warnings
(Need help? -> https://github.com/conventional-changelog/commitlint#what-is-commitlint )
# 或者
$ commitlint "docs: asdf"
⧗ input: build(npm): 添加package.json
✔ found 0 problems, 0 warnings
(Need help? -> https://github.com/conventional-changelog/commitlint#what-is-commitlint )
## `husky`
### 安装
# 本地
$ npm install --save-dev husky
### 配置
`package.json`中添加
// package.json
{
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}
`git`提交信息提交`commitlint`检查,参数`-E`默认将`.git/COMMIT_EDITMSG`数据添加到`HUSKY_GIT_PARAMS`
### 测试
# 错误提交提交
$ git commit -m "忽略node_modules"
husky > commit-msg (node v10.15.3)
⧗ input: 忽略node_modules
✖ subject may not be empty [subject-empty]
✖ type may not be empty [type-empty]
✖ found 2 problems, 0 warnings
(Need help? -> https://github.com/conventional-changelog/commitlint#what-is-commitlint )
husky > commit-msg hook failed (add --no-verify to bypass)
# 正确提交
$ git commit -m "build(npm): 忽略node_modules"
husky > commit-msg (node v10.15.3)
⧗ input: build(npm): 忽略node_modules
✔ found 0 problems, 0 warnings
(Need help? -> https://github.com/conventional-changelog/commitlint#what-is-commitlint )
[master 8728336] build(npm): 忽略node_modules
1 file changed, 1 insertion(+)
create mode 100644 .gitignore
### 禁用`husky`
某一次提交想要禁用`husky`,可以添加参数`--no-verify`
$ git commit --no-verify -m "xxx"
## `CI`设置
`Travis CI`为例
在本地安装
$ npm install --save-dev @commitlint/travis-cli
修改`travis.yml`
language: node_js
script:
- commitlint-travis

View File

@@ -0,0 +1,85 @@
# [Commitizen]信息交互工具
[Commitizen](http://commitizen.github.io/cz-cli/)是一个提交日志工具,辅助开发者使用提交规则
## 预配置
需要安装`NodeJS`,参考:[nodeJS安装](https://hexo-guide.readthedocs.io/zh_CN/latest/node/nodeJS%E5%AE%89%E8%A3%85.html)
## 安装`Commitizen`
# 全局安装
$ npm install -g commitizen
## 安装`Adapter`
`Commitizen`支持多种不同的提交规范,可以安装和配置不同的适配器实现
`Conventional Commit`规范为例
### 全局配置(推荐)
# 安装
$ npm install -g cz-conventional-changelog
# 配置
$ echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc
### 本地配置
# 安装
commitizen init cz-conventional-changelog --save-dev --save-exact
安装完成后,查看是否在`package.json`中已加入`cz-conventional-changelog`信息:
```
...
...
"devDependencies": {
"cz-conventional-changelog": "^3.0.2"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
```
### 测试
安装完成后,使用`git-cz`替代`git commit`完成提交操作,
```
$ git cz
cz-cli@4.0.3, cz-conventional-changelog@3.0.2
? Select the type of change that you're committing: (Use arrow keys)
feat: A new feature
fix: A bug fix
docs: Documentation only changes
style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
refactor: A code change that neither fixes a bug nor adds a feature
perf: A code change that improves performance
test: Adding missing tests or correcting existing tests
(Move up and down to reveal more choices)
```
通过提示信息辅助你完成标准化的提交日志
**`git-cz`支持`git commit`所有的参数设置**
**正文换行使用`\n`操作,比如正文内容如下:`新增事项:\n1. 测试1\n2. 测试2\n3. 测试`**
build(npm): 加入package.json
新增事项:
1. 测试1
2. 测试2
3. 测试
## 徽章
`README`中添加`commitizen`友好徽章
[![](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)

View File

@@ -39,9 +39,14 @@ extra_javascript:
nav:
- Home: index.md
- 规范:
- GIT工作流: workflow/index.md
- README:
- 引言: readme/index.md
- '[译]规范': readme/译-规范.md
- '徽章': readme/badge.md
- 后记: readme/postscript.md
- GIT工作流: workflow/index.md
- MESSAGE:
- 引言: message/index.md
- '[gitmessage]提交模板': message/gitmessage.md
- 'Conventional提交规范': message/conventional-commit.md
- 'Angular提交规范': message/angular-commit.md