Problems with entering Git commit message with Vim

GitCommitMessage

Git Problem Overview


OS: Windows

I write

$ git commit

then

> "# Please enter the commit message"

I write some text, like

> "Form validation added"

Press Enter and not commited. Then i press Shift+Enter, Ctrl+Enter, Alt+Enter - still not commited.

I think its stupid trouble, but What i must to do?

Git Solutions


Solution 1 - Git

If it is VIM for Windows, you can do the following:

  • enter your message following the presented guidelines
  • press Esc to make sure you are out of the insert mode
  • then type :wqEnter or ZZ.

Note that in VIM there are often several ways to do one thing. Here there is a slight difference though. :wqEnter always writes the current file before closing it, while ZZ, :xEnter, :xiEnter, :xitEnter, :exiEnter and :exitEnter only write it if the document is modified.
All these synonyms just have different numbers of keypresses.

Solution 2 - Git

I am assuming you are using msys git. If you are, the editor that is popping up to write your commit message is vim. Vim is not friendly at first. You may prefer to switch to a different editor. If you want to use a different editor, look at this answer: https://stackoverflow.com/questions/1634161/how-do-i-use-notepad-or-other-with-msysgit/1635493#1635493

If you want to use vim, type i to type in your message. When happy hit ESC. Then type :wq, and git will then be happy.

Or just type git commit -m "your message here" to skip the editor altogether.

Solution 3 - Git

Have you tried just going: git commit -m "Message here"

So in your case:

git commit -m "Form validation added"

After you've added your files of course.

Solution 4 - Git

Typically, git commit brings up an interactive editor (on Linux, and possibly Cygwin, determined by the contents of your $EDITOR environment variable) for you to edit your commit message in. When you save and exit, the commit completes.

You should make sure that the changes you are trying to commit have been added to the Git index; this determines what is committed. See http://gitref.org/basic/ for details on this.

Solution 5 - Git

You can change the comment character to something besides # like this:

git config --global core.commentchar "@"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionaTeiView Question on Stackoverflow
Solution 1 - GitmousioView Answer on Stackoverflow
Solution 2 - GitMatt GreerView Answer on Stackoverflow
Solution 3 - GitTonyView Answer on Stackoverflow
Solution 4 - GitEmil SitView Answer on Stackoverflow
Solution 5 - GitMatt SpradleyView Answer on Stackoverflow