erlxtg
Last Updated: May 29, 2017
·
5.307K
· caioariede
00f1bf67a52fc75fb6da011edcf3f42b

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.

Say Thanks
Respond

5 Responses
Add your response

932
99218a2893ac76af03ca5cecc6f5b54f

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
2c5e57a455c12b4dcd500e241cc00fd5

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

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

over 1 year ago ·
1041
4115ea8d902312642412bc42f36f0559

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
81240c09013ffcdab4fde148eba0d620

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

over 1 year ago ·
12192
Bc0ed56199778bc7693053b278a37c8e

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