Git actually checks the exit code of whatever editor you have configured and outputs that error message if it's non-zero.
I couldn't replicate the problem with your commands but you may have better luck. Simply run
vim normally (i.e., not via
git), enter the
:wq commands (and whatever else you did in between those two), then check the exit code with (for Linux)
If that's not zero, you at least have a repeatable test you can use for further investigation, at which point you can start experimenting with
vim options (as shown in this question for example).
You could also opt for a different editor which doesn't return non-zero. There's probably no reason to need the massive power of Vim for composing what are (hopefully) one-liner commit messages.
In fact, I don't use any editor, instead relying on the command-line bevaviour only. For one-liners:
pax$ git commit -m "Fixed my co-worker's atrocious code :-)"
or, more more complex messages:
pax$ git commit -F -
(reading log message from standard input)
Fixed my co-worker's atrocious code, specifically:
- no comments;
- unreadable formatting;
- bad variable names.
As to how you easily get at the comment you just tried to use, that should be stored in
.git/COMMIT_EDITMSG so you can just use:
git commit -F .git/COMMIT_EDITMSG
-eF if you want to check or further edit the message).