我是怎麼寫 Git Commit message 的?

做用

編寫格式化的 commit message 可以大大提升代碼的維護效率。html

好比:git

  • 能夠提供更多的歷史信息,方便快速瀏覽;
  • 能夠過濾某些 commit(好比文檔改動),便於快速查找信息;
  • 能夠直接從 commit 生成 Change log

用的什麼規範?

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

其中,Header 是必需的,Body 和 Footer 能夠省略。npm

type

type 用於說明 commit 的類別。gulp

  • feature A new feature
  • fix A bug fix
  • docs Documentation only changes
  • style Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • refactor A code change that neither fixes a bug nor adds a feature
  • perf A code change that improves performance
  • test Adding missing tests or correcting existing tests
  • build Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
  • ci Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
  • chore Other changes that don't modify src or test files
  • revert Reverts a previous commit

scope

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

subject

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

body

Body 部分是對本次 commit 的詳細描述,能夠分紅多行。ui

footer

BREAKING CHANGE,用來描述當前 commit 與上一個版本不兼容的地方。spa

Issue,用來描述當前 commit 針對的某個issue。插件

參考文章

Commit message 和 Change log 編寫指南code

用的什麼輔助工具?

太教條了,太累... 給你們分享一個我使用的工具。

JetBrains IDE 插件,在 GoLandPhpStorm 中 均可以在插件市場搜索 Git Commit Message Helper

插件地址:Git Commit Message Helper

安裝後效果,在 git commit 時:

g-1.png

g-2.png

我們看一下效果:

g-3.png

g-4.png

這時,點擊 Commit 或 Commit and Push... 便可。

趕快去體驗吧。

推薦閱讀

相關文章
相關標籤/搜索