erlxtg
Last Updated: May 29, 2017
·
6.718K
· 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

932

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 ·
981

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

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

over 1 year ago ·
1041

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 ·
4795

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

over 1 year ago ·
12192

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 ·
Filed Under