git: abort commit in the middle of typing message
If you have vim opened to write your commit message just delete the lines that don't start with # and git will abort your commit
Aborting commit due to empty commit message.
If your editor can exit with an error code -- Git will abort the commit. When using VIM, type
:cq
to exit with an non-zero error code and abort the commit.
Yes. Write the commit message to a different file (:w /some/other/path.txt
). Then exit the editor without saving (:q!
). If you previously saved the file to its original path, delete everything and write the empty file first (an empty commit message will abort the commit).
Now, when you're ready to commit "for reals", use the message file you saved at the alternate path.
Alternately, copy the commit message into one of vim's buffers.
It's worth noting that you really don't have to do this at all: commit --amend
lets you alter the commit after it's made, so the easy solution is to produce the commit with what you've got and then fix it before pushing. You can even just finish the commit in its broken state, reset HEAD~
(resets you to the state your working copy was in before the commit), fix your working copy, and then commit -a -c HEAD@{1}
to use the old commit message.