Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exit Vim without committing changes in Git

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?

like image 265
j0fb Avatar asked May 16 '13 19:05

j0fb


People also ask

How do you exit git commit amend without saving?

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).

How do I exit VI in git?

Exiting Vim If you want to save your changes and quit, press Esc then type :wq and hit Enter or ↵ or on Macs, Return .

How do I save and exit Vim in git?

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.


2 Answers

: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.

like image 140
EDY ARMENDARIZ Avatar answered Oct 12 '22 02:10

EDY ARMENDARIZ


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.

like image 28
Ingo Karkat Avatar answered Oct 12 '22 02:10

Ingo Karkat