256

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

377

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).
6
  • 2
    It's then <esc> ZZ, to make sure you are in normal mode.
    – Ikke
    Jan 14, 2015 at 10:38
  • 3
    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"?
    – Martin P.
    Dec 16, 2016 at 12:46
  • 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. Jan 12, 2017 at 23:44
  • @marvelTracker correct, esc in indeed to get out of insert modes, then you can execute commands like ZZ or :wq
    – Ikke
    Jan 14, 2017 at 7:44
  • @Martin P. ... those are keys, on your keyboard. Jun 7, 2017 at 20:27
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
  • 5
    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 Nov 25, 2014 at 18:44
  • 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. Jun 28, 2018 at 22:47
  • 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.
    – Chase
    Apr 30, 2020 at 23:49
52

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

3
  • 1
    This was exactly what I needed! Thanks!
    – praty
    Apr 26, 2018 at 5:55
  • 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. May 31, 2020 at 20:24
  • Not working with me in windows and working in ubuntu
    – Ravi Singh
    Sep 28, 2021 at 10:14
16

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
  • This is very helpful! I was wondering how to do multi-line commit messages Jan 31, 2020 at 16:27
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.

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.