When I use git commit --amend
or git rebase -i
, vim opens up for me to make changes. If I then change my mind and exit vim without making any changes, a commit is still made which shows up in git reflog
.
How do I exit the editor without committing anything?
If you want to exit without saving hit escape, :q! and enter. git opens your default editor so you can edit the commit message. You can change the default editor, even to graphical text editors (such as Sublime Text).
Exiting Vim If you want to save your changes and quit, press Esc then type :wq and hit Enter or ↵ or on Macs, Return .
To save a file in Vim / vi, press Esc key, type :w and hit Enter key. One can save a file and quit vim / Vi by pressing Esc key, type :x and hit Enter key.
:cq!
This will force an error to Vim and it will not save any changes. Link to Vim manual.
You may want to use cq
without !
if you want vim
to exit with an error and without saving.
When you haven't made changes and saved them, :q!
could suffice (in a plain commit; when you're not amending), but if you are like me, chances are you've already (even unconsciously) persisted the edited message.
Git (and other such tools that use Vim to edit a message) will abort the entire process (and ignore any saved changes to the message) if the editor quits with a non-success exit status. You can do that in Vim with the :cq[uit]!
command.
You may want to use cq
without !
if you want vim
to exit with an error and without saving.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With