Git commit message 撰寫和改進實例: mini-arm-os
-
重新建立一段程式碼的脈絡是非常浪費的事情。我們無法避免這件事情的複雜性,因此我們應將心力放在儘可能的降低複雜度。Commit messages 正可以做到這點,而我們可以從 commit message 看出一個開發者是不是一位好的合作對象。
-
一個精心撰寫的 log 是漂亮以及有用的。git blame
、revert
、rebase
、log
、shortlog
以及其他相關的指令會進入到你的生活中。
-
一個 diff
可以告訴你什麼改變了,但是只有 commit message 可以正確的告訴你為什麼
-
文中提到為什麼我們會不注意 git commit
原因總歸沒有花很多時間使用 git log
以及相關的指令
-
團隊之間撰寫 commit log 的方式應該要相同。為了建立一個有用的修訂紀錄,團隊應該要先統一其 commit message 的風格,並且至少定義以下三件事情:
- 風格. Markup syntax,wrap margins,文法,大寫慣例,符號慣例。定義這些事情,不要用猜的,並且讓它愈簡單愈好。最後的結果會得到一個非常一致的 log,不僅讓人們可以閱讀體會閱讀的樂趣,還能讓人定期的去閱讀它們。
- 內容. 什麼樣的資訊需要放置在 commit message body 中?什麼不需要?
- Metadata. issue tracking IDs, pull request 號碼等等的資料該如何被參照?
重要的七大規則
- 用一行空白行分隔標題與內容
- 限制標題最多只有 50 字元
- 標題開頭要大寫
- 標題不以句點結尾
- 以祈使句撰寫標題
- 內文每行最多 72 字
- 用內文解釋 what 以及 why vs. how
用一行空白行分隔標題與內容
$ git log --oneline -5 <branch>
我的版本
這就是沒有空行的壞處Yen-Kwan Wu
Jserv 修改過的版本
$ git shortlog -5 fix_exp_ret_behavior
內文每行最多 72 字
排版上會比較好看、整潔
我的版本
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Jserv 修改過的版本
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
用內文解釋 what 以及 why vs. how
Good Example
我原本的commit
修改過後的