Skip to main content

Angular规范

参考文献

  • 查看历史提交
git log <last tag> HEAD --pretty=format:%s
  • 仅显示本次发布新增加的功能
$ git log <last release> HEAD --grep feature

基础格式

<type>(<scope>): <subject>  # Heander
# 空一行 Body
<body>
# 空一行 Footer
<footer>
<必选类型>(<影响范围>): <必须短描述>  # Heander
# 空一行 Body
<可选长描述>
# 空一行 Footer
<可选脚注>

Header 是必需的,Body 和 Footer 可以省略

  • Header:关键信息 (type)(scope):(subject)
  • type:用于说明 commit 的类别,只允许使用下面7个标识。
  • scope:本次commit 影响的范围,比如数据层、控制层、视图层等等
  • subject:commit 目的的简短描述,不超过50个字符(必需)
  • Body对本次 commit 的详细描述,可以分成多行。
  • Footer只用于两种情况,不兼容的变动针对某个issue

Type

语法:

<type>(<scope>): <subject>

只允许使用下面7个标识,用来说明commit的类别

  • feat:新功能(feature)
  • fix:修补bug
  • docs:仅仅修改了文档,比如README, CHANGELOG, CONTRIBUTE等等
  • style: 仅仅修改了空格、格式缩进等等,不改变代码逻辑
  • refactor:重构(即不是新增功能,也不是修改bug的代码变动)
  • test:测试用例,包括增加缺失用例或者修正测试用例
  • chore:构建过程或辅助工具的变动
  • perf: 优化相关,比如提升性能、体验
  • ci:更改我们的CI配置文件和脚本
  • revert:用于撤销以前的 commit,后面跟着被撤销 Commit 的 Header。

如果typefeat 和 fix,则该 commit 将肯定出现在 Change log 之中。

其他情况(docs、chore、style、refactor、test)由你决定,要不要放入 Change log,建议是不要。

示例:

# 类型(大概变动的文件位置): 简短说明
feat(src/compent/context): 新增右键查看功能

Scope

scope用于说明 commit 影响的范围,比如数据层、控制层、视图层等等,视项目不同而不同。

示例:


Subject

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

  • 以动词开头,使用第一人称现在时,比如change,而不是changed或changes
  • 第一个字母小写
  • 结尾不加句号(.)
常用动词作用
change
<type>(<scope>): <short summary>
│ │ │
│ │ └─⫸ Summary in present tense. Not capitalized. No period at the end.
│ │
│ └─⫸ Commit Scope: The scope should be the name of the component affected
(as perceived by the person reading the
│ changelog generated from commit messages).

└─⫸ Commit Type: build|ci|docs|feat|fix|perf|refactor|test

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

注意点:

  1. 使用第一人称现在时,比如使用change而不是changed或changes
  2. 应该说明代码变动的动机(原因),以及与以前行为的对比。

Footer 并不常用,它只会在以下两种场景出现:

  1. 不兼容变动

    前代码与上一个版本不兼容,则 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.
  2. 针对指定的 issue

    如果当前 commit 针对某个issue,那么可以在 Footer 部分关闭这个 issue 。

    示例:

    # 关闭单个
    Closes #234

    # 关闭多个
    Closes #123, #245, #992

Revet (特殊情况)

如果当前 commit 用于撤销以前的 commit,则必须以revert:开头,后面跟着被撤销 Commit 的 Header。

revert: feat(pencil): add 'graphiteWidth' option This reverts commit 667ecc1654a317a13331b17617d973392f415f02. # 被撤销的HEADER

Body部分的格式是固定的,必须写成This reverts commit <hash>.,其中的hash是被撤销 commitSHA 标识符。

如果当前 commit 与被撤销的 commit,在同一个发布(release)里面,那么它们都不会出现在 Change log 里面。

如果两者在不同的发布,那么当前 commit,会出现在 Change log 的Reverts小标题下面。

commitlint + husky 校验每次的commit格式

Change-log