Last Updated: May 29, 2017
·
14.83K
· caioariede

Vim: Quit with an error code (eg. to prevent Git from committing)

If you want to prevent Git from committing after editing the commit message, do:

:cq

This will make Vim to quit with an error code, preventing the commit operation from proceed.

5 Responses
Add your response

Nice. Suggested mnemonic, "cancel-y quit"... "commit quitter"...

I've just had been leaving an empty commit message; git then cancels the commit.

over 1 year ago ·

Brevity is the soul of vim. :-) Great tip.

@alxndr: "Call-it quits", maybe?

over 1 year ago ·

You can also quit without writing to avoid a commit. This command is nice because it's useful in lots of situations.

:q!
over 1 year ago ·

Caution: your changes won't be saved by :cq

over 1 year ago ·

Watch out! If you're doing a git commit --amend, then you need :cq, otherwise you'll regenerate the commit with the same message (if you already pushed... d'oh).

over 1 year ago ·