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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40906322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:28:12  来源:igfitidea点击:

How to abort 'git commit --amend'?

git

提问by Flip

I accidentally used git commit --amend. My text editor is open and waiting for input. I know, that when I close it now (not changing the existing commit message) the commit will be amended. What can I do to abort the process?

我不小心用了git commit --amend。我的文本编辑器已打开,正在等待输入。我知道,当我现在关闭它(不更改现有提交消息)时,提交将被修改。我该怎么做才能中止该过程?

This blog articlesays that I can simply delete the commit message and the commit will then not be valid and ignored. Is that correct? Are there alternatives?

这篇博客文章说我可以简单地删除提交消息,然后提交将无效并被忽略。那是对的吗?有替代品吗?

回答by djb

That is correct. Saving the file with no contents will abort the amend.

那是正确的。保存没有内容的文件将中止修改。

回答by aug

Adding another answer to this, you can also do

对此添加另一个答案,您也可以这样做

:cq

:cq

to abort the amend in Vim which tells it to quit with an error code, causing Git to abort with:

中止 Vim 中的修改,它告诉它以错误代码退出,导致 Git 中止:

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

From Vim's documentation:

来自 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.

回答by pedrorijo91

delete the message. an empty message will abort any commit (amend is just a 'special' commit)

删除消息。空消息将中止任何提交(修改只是一个“特殊”提交)

回答by fan123199

Yes, deleting all message. Pay attention to the annotationthat auto-created by git, you should delete them all.

是的,删除所有消息。注意git自动创建的注解,应该全部删除。