Git
如果由於某種原因送出失敗,git commit 消息是否可以恢復?
git commit
可能因gpg.commitsign = true
&&gpg
失敗(無論出於何種原因)等原因而失敗。重試該命令會打開一個空白編輯器;消息失去。發生這種情況時,是否有任何方法可以恢復書面送出消息,以使用相同的消息重試送出?
來自
man git-commit
:FILES $GIT_DIR/COMMIT_EDITMSG This file contains the commit message of a commit in progress. If git commit exits due to an error before creating a commit, any commit message that has been provided by the user (e.g., in an editor session) will be available in this file, but will be overwritten by the next invocation of git commit.
因此,與其 repeat
git commit
,不如使用上一條消息重試可以使用:$ git commit -m "$(cat .git/COMMIT_EDITMSG)"
或者一般情況下(例如適用於別名):
$ git commit -m "$(cat "$(git rev-parse --git-dir)/COMMIT_EDITMSG)")"