commit message的格式
每次提交,Commit message 都包括三個部分:Header,Body 和 Footer。
<type>(<scope>): <subject> // 空一行 <body> // 空一行 <footer>
其中,Header 是必需的,Body 和 Footer 可以省略。
不管是哪一個部分,任何一行都不得超過72個字符(或100個字符)。這是為了避免自動換行影響美觀。
Header
Header部分只有一行,包括三個字段:type(必需)、scope(可選)和subject(必需)。
(1)type
type用於說明 commit 的類別,只允許使用下面7個標識。
feat:新功能(feature)
fix:修補bug
docs:文檔(documentation)
style: 格式(不影響代碼運行的變動)
refactor:重構(即不是新增功能,也不是修改bug的代碼變動)
test:增加測試
chore:構建過程或輔助工具的變動
如果type為feat和fix,則該 commit 將肯定出現在 Change log 之中。其他情況(docs、chore、style、refactor、test)由你決定,要不要放入 Change log,建議是不要。
(2)scope
scope用於說明 commit 影響的范圍,比如數據層、控制層、視圖層等等,視項目不同而不同。
(3)subject
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
有兩個注意點。
(1)使用第一人稱現在時,比如使用change而不是changed或changes。
(2)應該說明代碼變動的動機,以及與以前行為的對比。
Footer
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
也可以一次關閉多個 issue 。
Closes #123, #245, #992
Revert
還有一種特殊情況,如果當前 commit 用於撤銷以前的 commit,則必須以revert:開頭,后面跟着被撤銷 Commit 的 Header。
revert: feat(pencil): add 'graphiteWidth' option This reverts commit 667ecc1654a317a13331b17617d973392f415f02.
Body部分的格式是固定的,必須寫成This reverts commit <hash>.,其中的hash是被撤銷 commit 的 SHA 標識符。
如果當前 commit 與被撤銷的 commit,在同一個發布(release)里面,那么它們都不會出現在 Change log 里面。如果兩者在不同的發布,那么當前 commit,會出現在 Change log 的Reverts小標題下面。
