aTei
aTei

Reputation: 1844

Problems with entering Git commit message with Vim

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?

Upvotes: 154

Views: 162439

Answers (5)

Matt Spradley
Matt Spradley

Reputation: 8444

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

git config --global core.commentchar "@"

Upvotes: 0

mousio
mousio

Reputation: 10337

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.

Upvotes: 255

Matt Greer
Matt Greer

Reputation: 62057

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: How do I use Notepad++ (or other) with msysgit?

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.

Upvotes: 48

Emil Sit
Emil Sit

Reputation: 23562

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.

Upvotes: 1

Tony
Tony

Reputation: 933

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.

Upvotes: 17

Related Questions