Help, I am stuck in Vim after git commit
git commit without -m opens an editor, often Vim. Here is how to save the commit or cancel it, and how to never land there again.
git commit # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # On branch main # Changes to be committed: # modified: index.html #
The fix
- Esc
Gets you out of whatever mode you are in. Pressing it twice does no harm.
- i
Insert mode. Type your commit message on the first, empty line, above the lines that start with
#. - Esc
Back to normal mode.
- :wqEnter
Write and quit. Git saves the commit with your message.
- Esc
Back to normal mode first.
- :cqEnter
Quits with an error, so Git cancels the commit. Your staged changes stay staged.
Only :cq is a sure cancel. :q! cancels a plain git commit because the message is still empty, but for amend, merge, revert or rebase Git has already filled in a message, so :q! goes ahead with it. After a merge, :cq stops only the commit: git merge --abort then undoes the merge. After a revert, git reset --merge does the same.
Why this works
Without a message, Git opens your default editor so you can write one, and on many systems that is Vim. Vim starts in a mode where typing does not insert text, which is why it feels stuck. Next time, pass the message right away with git commit -m "message", or switch to a friendlier editor once: git config --global core.editor nano.