如何规范 Git Message

栏目: 编程工具 · 发布时间: 6年前

内容简介:每次提交,Commit message 都包括包括三个字段:type(必需)、scope(可选)和 subject(必需)。scope用于说明subject是
  • 加快 Reviewing Code 的过程
  • 帮助我们写好 release note
  • 5年后帮你快速想起来某个分支,tag 或者 commit 增加了什么功能,改变了哪些代码
  • 让其他的开发者在运行 git blame 的时候想跪谢
  • 总之一个好的提交信息,会帮助你提高项目的整体质量
  • 更专业化管理好你的项目,提高项目完整性

Angular 规范的 Commit message 格式(正统规范)

每次提交,Commit message 都包括包括三个字段:type(必需)、scope(可选)和 subject(必需)。

type 用于说明 commit 的类别,只允许使用下面9个标识。

  • WIP work in progress 向前推进
  • feat 新功能(feature)
  • fix 修补bug
  • docs 文档(documentation)
  • style 格式(不影响代码运行的变动)
  • refactor 重构(即不是新增功能,也不是修改bug的代码变动)
  • test 增加测试
  • chore 构建过程、辅助 工具 的变动
  • revert 回退一次提交

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

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

  • 以动词开头,使用第一人称现在时,比如 change,而不是 changed 或 changes
  • 第一个字母大写
  • 结尾不加句号

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
复制代码

准备工作

确保自己环境已安装 Node, 本次主要依赖两个 Node 工程, npm install -g commitizen 全局安装 commitizen 工程。 npm i -g cz-customizable 全局安装 cz-customizable 工程。 同时在~/ 或项目目录下创建 .cz-config.js 文件, 拷贝下面代码到该文件。

'use strict';

module.exports = {

  types: [
    { 
      value: 'WIP',
      name : ':muscle:  WIP:      Work in progress'
    },
    { 
      value: 'feat',
      name : ':sparkles:  feat:     A new feature'
    },
    { 
      value: 'fix',
      name : ':beetle:  fix:      A bug fix'
    },
    { 
      value: 'refactor',
      name : '     refactor: A code change that neither fixes a bug nor adds a feature'
    },
    { 
      value: 'docs',
      name : ':books:  docs:     Documentation only changes'
    },
    { 
      value: 'test',
      name : ':rotating_light:  test:     Add missing tests or correcting existing tests'
    },
    { 
      value: 'chore',
      name : '     chore:    Changes that don\'t modify src or test files. Such as updating build tasks, package manager'
    },
    { 
      value: 'style',
      name : ':nail_care:  style:    Code Style, Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)'
    },
    { 
      value: 'revert',
      name : ':rewind:  revert:   Revert to a commit'
    }
  ],

  scopes: [],

  allowCustomScopes: true,
  allowBreakingChanges: ["feat", "fix"]
};

复制代码

删除 cz-customizable 工程中 questions.js 中 关于 footer 部分,认为暂时不需要(也可以注释掉,后续需要再加回来)。

上述共工作完成后,使用git cz 代替 git commit 提交你的代码。


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Design Accessible Web Sites

Design Accessible Web Sites

Jeremy Sydik / Pragmatic Bookshelf / 2007-11-05 / USD 34.95

It's not a one-browser web anymore. You need to reach audiences that use cell phones, PDAs, game consoles, or other "alternative" browsers, as well as users with disabilities. Legal requirements for a......一起来看看 《Design Accessible Web Sites》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具