在正式參與項目開發之前,瞭解並且堅持使用一些規範更方便我們與同事之間的合作。這些通常是約定俗成的。
git提交準則
git源碼中的Documentation/SubmittingPatches列舉了git提交規範相關的說明文檔。
提交之前的注意事項
1、檢查空白錯誤
git diff --check #確認將提交的內容中有無空白信息
2、嘗試讓每一個提交成爲一個邏輯上的獨立變更集
儘量使每一筆提交都成爲獨立的patch,這讓同事審查你的改動時儘量讓事情容易些。
3、重寫提交歷史
正式提交之前,可以通過修改本地提交歷史讓提交後的信息更加易懂。
4、規範化提交信息
這裏有份Tim Pope 寫的模板,看看怎樣纔是規範的提交描述。稍後我們手動創建一個git message提交模板。
創建git message模板
1、git config
mi@ubuntu:~$ git config --global -e
....
#添加
[commit]
template = /home/mi/.gitmessage
2、配置模板
mi@ubuntu:~$ vim ~/.gitmessage
#title [where/what]
#JIRA-ID
#brief description for this bug [what/why]
#Change-Id:auto-generate
3、提交使用模板
mi@ubuntu:~$ git commit -s #儘量不用 git commit -m "xx"
4、查看提交記錄
mi@ubuntu:~$ git log --no-merges
參考鏈接