265

I run git from the command line.

How does one save the commit message?

I mean what keys should I press to go past this screen:

Commit message interface

6 Answers 6

389

You are inside vim. To save changes and quit, type:

<esc> :wq <enter>

That means:

  • Press Escape. This should make sure you are in command mode
  • type in :wq
  • Press Return

An alternative that stdcall in the comments mentions is:

  • Press Escape
  • Press shift+Z shift+Z (capital Z twice).
Sign up to request clarification or add additional context in comments.

6 Comments

It's then <esc> ZZ, to make sure you are in normal mode.
I testes everything for about half an hour till i got the fact, that entering [shift] + [z,z] brings me out of this editor in windows!! What is :wq ? I was even not able to type in another message, although i was able to delte the old message. Is there any reference of shortcuts or something like that, to learn how to navigate through this "editor"?
For me I had to press <esc> and then [shift] + [z,z] . I think <esc> is to get out from insert mode. This may help to someone else.
@marvelTracker correct, esc in indeed to get out of insert modes, then you can execute commands like ZZ or :wq
@Martin P. ... those are keys, on your keyboard.
|
63

I believe the REAL answer to this question is an explanation as to how you configure what editor to use by default, if you are not comfortable with Vim.

This is how to configure Notepad for example, useful in Windows:

git config --global core.editor "notepad"

Gedit, more Linux friendly:

git config --global core.editor "gedit"

You can read the current configuration like this:

git config core.editor

3 Comments

Notepad doesn't write files with Unix line endings, and cannot be used (alone) as the core.editor. GitPad, or another wrapper, is required. github.com/github/GitPad
I'd recommend using nano to stay in the terminal rather than launching a text editor app. It's much easier to use than vim and actually shows you what commands are available at the bottom of the screen.
If this doesn't work because (like me) you're using WSL, you can reset core.editor to default using git config --global --unset-all core.editor. If there's some way to use Notepad with WSL, that would be perfect though.
54

You can also commit with git commit -m "Message goes here" That's easier.

2 Comments

This should really be the accepted answer. It is the most concise way to publish a commit including a message from CMD/Bash without using any editor at all.
Not working with me in windows and working in ubuntu
18

If you enter git commit but omit to enter a comment using the –m parameter, then Git will open up the default editor for you to edit your check-in note. By default that is Vim. Now you can do two things:

Alternative 1 – Exit Vim without entering any comment and repeat

A blank or unsaved comment will be counted as an aborted attempt to commit your changes and you can exit Vim by following these steps:

  1. Press Esc to make sure you are not in edit mode (you can press Esc several times if you are uncertain)

  2. Type :q! enter
    (that is, colon, letter q, exclamation mark, enter), this tells Vim to discard any changes and exit)
    Git will then respond:

    Aborting commit due to empty commit message

    and you are once again free to commit using:

    git commit –m "your comment here"
    

Alternative 2 – Use Vim to write a comment

Follow the following steps to use Vim for writing your comments

  1. Press i to enter Edit Mode (or Insert Mode).
    That will leave you with a blinking cursor on the first line. Add your comment. Press Esc to make sure you are not in edit mode (you can press Esc several time if you are uncertain)
  2. Type :wq enter
    (that is colon, letter w, letter q, enter), this will tell Vim to save changes and exit)

Response from https://blogs.msdn.microsoft.com/kristol/2013/07/02/the-git-command-line-101-for-windows-users/

1 Comment

This is very helpful! I was wondering how to do multi-line commit messages
14

Press Shift-zz. Saves changes and Quits. Escape didn't work for me.

I am using Git Bash in windows. And couldn't get past this either. My commit messages are simple so I dont want to add another editor atm.

Comments

0

If the usual means of exiting message mode aren't working for you, try ctrl-c. I was on a remote PC, and this ended up being the solution.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.