簡體   English   中英

如何中止'git commit --amend'?

[英]How to abort 'git commit --amend'?

我不小心使用了git commit --amend 我的文本編輯器已打開,正在等待輸入。 我知道,當我現在關閉它(不更改現有提交消息)時,提交將被修改。 我該怎么做才能中止該過程?

這篇博客文章說我可以簡單地刪除提交消息,然后提交將無效並被忽略。 那是對的嗎? 有替代品嗎?

那是正確的。 保存沒有內容的文件將中止修改。

對此添加另一個答案,您也可以這樣做

:cq

中止 Vim 中的修改,它告訴它以錯誤代碼退出,導致 Git 中止:

error: There was a problem with the editor 'Vim'.
Please supply the message using either -m or -F option.

來自 Vim 的文檔:

:cq[uit][!]             Quit Vim with an error code, so that the compiler
                        will not compile the same file again.
                        WARNING: All changes in files are lost!  Also when the
                        [!] is not used.  It works like ":qall!" :qall,
                        except that Vim returns a non-zero exit code.

刪除消息。 空消息將中止任何提交(修改只是一個“特殊”提交)

如果您刪除提交消息(無需刪除以#開頭的消息),您將中止git commit --amend命令。 你會得到這樣的輸出:

Aborting commit due to empty commit message.

注意事項:
刪除內容並執行:q! 仍然提交。 我不完全理解 ViM,所以,不能說為什么。

可以這么說,您還必須將最終的空/剩余內容寫入文件。 所以, :wq是。

是的,刪除所有消息。 注意git自動創建的注解,應該全部刪除。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM