1. 程式人生 > 其它 >Git Commit message 編寫指南

Git Commit message 編寫指南

目錄
git commit -m "hello world"

Commit message 的格式

每次提交,Commit message 都包括三個部分:Message header,Message body 和 Message footer。

<type>(<scope>): <subject>
// 空一行
<body>
// 空一行
<footer>

其中,Message header 是必需的,Message header 和 Message footer 可以省略。

不管是哪一個部分,任何一行都不得超過72個字元(或100個字元)。這是為了避免自動換行影響美觀。

Message header

Message header 部分只有一行,包括三個欄位:type(必需)、scope(可選)和subject(必需)。

type

type 用於說明 commit 的類別,只允許使用下面7個標識。

feat:新功能(feature)
fix:修補bug
docs:文件(documentation)
style:格式(不影響程式碼執行的變動)
refactor:重構(即不是新增功能,也不是修改bug的程式碼變動)
test:增加測試
chore:構建過程或輔助工具的變動

scope

scope 用於說明 commit 影響的範圍,比如資料層、控制層、檢視層等等,視專案不同而不同。

subject

subject 是 commit 目的的簡短描述,不超過50個字元。

Message body

Message 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

應該說明程式碼變動的動機,以及與以前行為的對比。

Message footer 部分只用於兩種情況。

  1. 不相容變動
  2. 關閉 Issue

Examples

feat($browser): onUrlChange event (popstate/hashchange/polling)

Added new event to $browser:
- forward popstate event if available
- forward hashchange event if popstate not available
- do polling when neither popstate nor hashchange available

Breaks $browser.onHashChange, which was removed (use onUrlChange instead)
fix($compile): couple of unit tests for IE9

Older IEs serialize html uppercased, but IE9 does not...
Would be better to expect case insensitive, unfortunately jasmine does
not allow to user regexps for throw expectations.

Closes #392
Breaks foo.bar api, foo.baz should be used instead
feat(directive): ng:disabled, ng:checked, ng:multiple, ng:readonly, ng:selected

New directives for proper binding these attributes in older browsers (IE).
Added coresponding description, live examples and e2e tests.

Closes #351
style($location): add couple of missing semi colons
docs(guide): updated fixed docs from Google Docs

Couple of typos fixed:
- indentation
- batchLogbatchLog -> batchLog
- start periodic checking
- missing brace
feat($compile): simplify isolate scope bindings

Changed the isolate scope binding options to:
  - @attr - attribute binding (including interpolation)
  - =model - by-directional model binding
  - &expr - expression execution binding

This change simplifies the terminology as well as
number of choices available to the developer. It
also supports local name aliasing from the parent.

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:

scope: {
  myAttr: 'attribute',
  myBind: 'bind',
  myExpression: 'expression',
  myEval: 'evaluate',
  myAccessor: 'accessor'
}

After:

scope: {
  myAttr: '@',
  myBind: '@',
  myExpression: '&',
  // myEval - usually not useful, but in cases where the expression is assignable, you can use '='
  myAccessor: '=' // in directive's template change myAccessor() to myAccessor
}

The removed `inject` wasn't generaly useful for directives so there should be no code using it.

參考

https://gitee.com/help/articles/4231

http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html

https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit

刻鵠不成尚類鶩,畫虎不成反類狗。