
是否可以使用來自標準輸出的提交訊息,例如:
echo "Test commit" | git commit -
也嘗試回顯 中的訊息內容.git/COMMIT_EDITMSG
,但隨後執行git commit
會要求在提到的檔案中新增變更。
答案1
您可以使用該-F <file>, --file=<file>
選項。
echo "Test commit" | git commit -F -
其用法在手冊頁中有描述git commit
:
從給定文件中獲取提交訊息。使用 - 從標準輸入讀取訊息。
答案2
你總是可以為它寫一個小函數:
gcm(){
read message
git commit -m "$message" "$@"
}
將其新增至您的~/.bashrc
shell 或等效的 shell 中,然後執行:
echo "Test commit" | gcm filename.to.commit
上面的命令將運行
git commit -m "Test commit" filename.to.commit