How to abort 'git commit --amend'?

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?

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


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


Adding another answer to this, you can also do

:cq

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

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

From Vim's documentation:

: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.

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


If you delete the commit message (no need to delete the ones starting with #) you will abort the git commit --amend command. You will get output like this:

Aborting commit due to empty commit message.