星期二, 10月 29, 2019

如何寫 Git commit message

主要是看 How to Write a Git Commit Message 這篇文章的紀錄,這篇文章是 2014 年的文,我可能有看過,印象中之前有看過介紹原則跟工具的文章。之前的印象,第一行要明確、簡單,不要太長。有細項,從第三行寫起,用 markdown 語法。
這篇一開始先講為什麼,作者不囉唆,直接要你看自己的 git log –oneline 輸出,看自己覺得 OK 不 OK。所以可讀性很重要,可以很快的看懂,那麼就可以不用費心再去看裏面改了什麼。
主要有7個原則:
  1. Separate subject from body with a blank line :第一行寫主旨,第三行開始寫內容。
  2. Limit the subject line to 50 characters :主旨不要超過 50 個字元
  3. Capitalize the subject line :主旨的第一個字元大寫
  4. Do not end the subject line with a period :主旨不要有句點
  5. Use the imperative mood in the subject line :主旨要用祈使句,就動詞+名詞
  6. Wrap the body at 72 characters :內容的每行不要超過 72 的字元
  7. Use the body to explain what and why vs. how :內容要儘可能描述做了什麼、為什麼這樣做跟如何做。

沒有留言: