154

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?

aTei
  • 1,844
  • 4
  • 15
  • 17
  • No problem. But your question would probably get better attention over at Super User, which is more on-topic for this type of non-programming question: http://superuser.com/questions/tagged/git – bzlm Apr 08 '11 at 18:25

5 Answers5

255

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.

mousio
  • 10,079
  • 4
  • 34
  • 43
  • Linked: [What to do after typing in commit message for git?](http://stackoverflow.com/questions/5048859/what-to-do-after-typing-in-commit-message-for-git) – mousio Apr 09 '11 at 07:36
  • 1
    When I enter `:wq` I see following message, ".git/COMMIT_EDITMSG" 54L, 2316C written Aborting commit due to empty commit message. – kanna Mar 15 '13 at 17:35
  • 1
    Make sure you've added a message. When prompted type something like "my message here" (you'll go into --insert mode-- I assume, press esc to leave it). Once you're done, and out of insert mode, then type 'ZZ' (capital ZZ) – Kpmurphy91 May 24 '13 at 07:21
  • 27
    Why, who came up with this? :wq Enter or ZZ sounds insane. – dezman Dec 10 '13 at 23:37
  • 1
    the `i` command to start inserting message text was extremely helpful. Thanks to @Matt Greer for that one. This answer was good for the rest of the steps. – ps2goat Dec 14 '15 at 21:04
  • Really helpful. So you need to go into insert mode, type your message, then hit esc, then type :wq. I wouldn't have figured it out and VIM is the default editor that comes up for me when using a new macbook pro. – AwfulPersimmon Feb 07 '23 at 22:44
48

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.

Community
  • 1
  • 1
Matt Greer
  • 60,826
  • 17
  • 123
  • 123
  • 18
    Is vim *ever* friendly? Or do people just get used to its unfriendliness? – Ryan Lundy Aug 17 '11 at 16:08
  • 8
    vim is friendly once you understand how it works. It's actually very logical and well thought out. – Matt Greer Aug 17 '11 at 19:59
  • If I want to use characters that require escaping (e.g. apostrophes) in the commit message I always use the vim editor because it's way less annoying. Otherwise I almost always just write the commit message as part of the commit command. – David DeMar Jan 09 '18 at 16:00
  • This is great when you need to amend a commit message – shinzou May 12 '19 at 14:46
17

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.

Tony
  • 933
  • 7
  • 15
  • 1
    Your variant good. But I want to go the way of what I wrote (google Translator) – aTei Apr 08 '11 at 18:23
  • No worries, I forgot that there was an editor after that command. I rarely ever just do git commit without an -m "Message" – Tony Apr 08 '11 at 18:37
1

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.

Emil Sit
  • 22,894
  • 7
  • 53
  • 75
0

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

git config --global core.commentchar "@"
Matt Spradley
  • 7,854
  • 9
  • 31
  • 40