252

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

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Jackson Publick
  • 2,545
  • 2
  • 13
  • 5

5 Answers5

375

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).
Ikke
  • 99,403
  • 23
  • 97
  • 120
  • 2
    It's then ZZ, to make sure you are in normal mode. – Ikke Jan 14 '15 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 '16 at 12:46
  • For me I had to press and then [shift] + [z,z] . I think is to get out from insert mode. This may help to someone else. – marvelTracker Jan 12 '17 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 '17 at 07:44
  • @Martin P. ... those are keys, on your keyboard. – hmcclungiii Jun 07 '17 at 20:27
  • `:x` is a shortcut for `:wq` to save and quit vim. If you want to learn to use vim, run `vimtutor`. – daviewales Feb 28 '20 at 22:11
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
Martin G
  • 17,357
  • 9
  • 82
  • 98
  • 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. https://github.com/github/GitPad – Edward Thomson Nov 25 '14 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. – Maybe_Factor Jun 28 '18 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 '20 at 23:49
52

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

Felipe Cabargas
  • 1,006
  • 7
  • 10
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.

Zacarias Bendeck
  • 951
  • 10
  • 7
14

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/

Sᴀᴍ Onᴇᴌᴀ
  • 8,218
  • 8
  • 36
  • 58
sitWolf
  • 930
  • 10
  • 16