[英]How to change default git commit message
我在prepare-commit-msg文件中的提交消息上添加了一些更改,然后執行了此命令
git config --global commit.template .git / hooks / prepare-commit-msg
之后,當我執行git commit時,我會收到類似的信息
我的更改的40行,然后
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# Explicit paths specified without -i nor -o; assuming --only paths...
# On branch master
# Changes to be committed:
#
# modified: test
#
問題是否有機會在頂部顯示此默認消息? 還是最好永久刪除此消息?
您似乎混淆了commit.template
選項(為git commit
的--template
選項提供默認值)與prepare-commit-message
掛鈎。
通常git commit
使用以下操作序列:
# Please enter the commit message ...
和git status
的輸出。 prepare-commit-message
鈎子(如果存在且可運行)。 $GIT_EDITOR
, core.editor
配置, $VISUAL
, $EDITOR
或內置默認值設置的,以第一個為准。) 如果使用-f
或-m
選項,通常會跳過步驟2、3和5(盡管您可以通過添加--edit
來強制git打開編輯器)。 大概您沒有使用過這些選項。
在什么--template
選項的作用,因此什么commit.template
不,是提供了一個文件的路徑名git commit
將在步驟2中這不會影響第3步中添加的行復制雖然路徑.git/hooks/prepare-commit-message
是 (可能)的文件的git可以閱讀,它不是你的模板一個非常明智的名字,因為如果同樣的路徑由可執行文件,該文件將成為可運行和步驟4可能會表現不好。
您可以通過添加--no-status
來告訴git commit
不執行步驟3。 (此外,-- --no-edit
有時也抑制步驟3,這是一個有點奇怪的副作用,-- --no-edit
也可以抑制步驟5。)
或者,您可以使用第4步消除部分或全部的git status
輸出和標准的# Please enter...
消息。 prepare-commit-message
掛鈎可以對模板文件進行任意更改。
請注意,-- --cleanup=<mode>
影響最終提交消息中的內容以及步驟6的處理。有關詳細信息,請參見git commit
文檔 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.