Git 如何在Commit時加入樣板template的機制

這個使用的情境是,當團隊有制式的Commit log需要遵守時,使用Commit template的機制,可以確保大家commit出去的log訊息好閱讀、追蹤issue。而針對個人也可以在 commit送出之前多一道程序看到自己送出前的log訊息。

先建立一個要來做為template的檔案,使用touch去新增,假設建立一個名為「.gitmessage.txt」的文字建來做為template
touch ~/.gitmessage.txt

建立之後再把template指令加入
git config commit.template ~/.gitmessage.txt

然後再用vi去寫入該template檔案
vi .gitmessage.txt

然後加入自訂內容的範本文字,假設每次commit都要加上issue no以及相關說明:
Ticket-No.
Comment:

再用「:wq」存檔離開

之後只要都使用「git commit」的指令,就會自動進入template內容,然後修改template內容之後「:wq」存檔離開就會自動寫入commit log了

Reference:
https://git-scm.com/book/zh-tw/v1/Git-客製化-Git-設定 https://stackoverflow.com/questions/21998728/how-to-specify-a-git-commit-message-template-for-a-repository-in-a-file-at-a-rel

留言

這個網誌中的熱門文章

ISO 27001 LA 主導稽核員 考照心得

Android如何實作強制App版本更新

如何實作從API抓取資料顯示在列表頁(ListView)上