如何規範 Git Message

爲何要關注提交信息

  • 加快 Reviewing Code 的過程
  • 幫助咱們寫好 release note
  • 5年後幫你快速想起來某個分支,tag 或者 commit 增長了什麼功能,改變了哪些代碼
  • 讓其餘的開發者在運行 git blame 的時候想跪謝
  • 總之一個好的提交信息,會幫助你提升項目的總體質量
  • 更專業化管理好你的項目,提升項目完整性

Angular 規範的 Commit message 格式(正統規範)

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

type 用於說明 commit 的類別,只容許使用下面9個標識。git

  • WIP work in progress 向前推動
  • feat 新功能(feature)
  • fix 修補bug
  • docs 文檔(documentation)
  • style 格式(不影響代碼運行的變更)
  • refactor 重構(即不是新增功能,也不是修改bug的代碼變更)
  • test 增長測試
  • chore 構建過程、輔助工具的變更
  • revert 回退一次提交

scope 用於說明 commit 影響的範圍,好比數據層、控制層、視圖層等等,視項目不一樣而不一樣github

subjectcommit 目的的簡短描述,不超過50個字符。npm

  • 以動詞開頭,使用第一人稱如今時,好比 change,而不是 changed 或 changes
  • 第一個字母大寫
  • 結尾不加句號

Body

Body 部分是對本次 commit 的詳細描述,能夠分紅多行。下面是一個範例。ruby

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 文件, 拷貝下面代碼到該文件。bash

'use strict';

module.exports = {

  types: [
    { 
      value: 'WIP',
      name : '💪  WIP:      Work in progress'
    },
    { 
      value: 'feat',
      name : '✨  feat:     A new feature'
    },
    { 
      value: 'fix',
      name : '🐞  fix:      A bug fix'
    },
    { 
      value: 'refactor',
      name : '🛠   refactor: A code change that neither fixes a bug nor adds a feature'
    },
    { 
      value: 'docs',
      name : '📚  docs:     Documentation only changes'
    },
    { 
      value: 'test',
      name : '🚨  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 : '💅  style:    Code Style, Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)'
    },
    { 
      value: 'revert',
      name : '⏪  revert:   Revert to a commit'
    }
  ],

  scopes: [],

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

複製代碼

刪除 cz-customizable 工程中 questions.js 中 關於 footer 部分,認爲暫時不須要(也能夠註釋掉,後續須要再加回來)。ide

上述共工做完成後,使用git cz 代替 git commit 提交你的代碼。工具

實際效果

參考文獻

ruby china 關於如何寫好 message
github.com/leonardoana…
github.com/angular/ang…
阿里南京技術專刊post

相關文章
相關標籤/搜索