308

I am using Windows and before committing, Git wants me to enter a text message and a new text window appears.

screenshot

How can I exit from this?

I am trying to learn Git. So, a little help will be highly appreciated.

johnsyweb
  • 129,524
  • 23
  • 177
  • 239
newbie
  • 4,435
  • 9
  • 29
  • 42
  • 2
    What text window? Screenshot it. – Blender Feb 07 '12 at 05:19
  • 1
    possible duplicate of [Git commit asking for comment](http://stackoverflow.com/questions/5668191/git-commit-asking-for-comment) – Cascabel Feb 07 '12 at 05:27
  • 1
    Odd, it claims the file is readonly... – johnny Feb 07 '12 at 09:01
  • @johnny: Now that *is* odd. Can you open that file in another editor? – johnsyweb Feb 07 '12 at 22:07
  • 1
    @Johnsyweb, I'm just reading the screenshot. It happened to me once too. I just removed the write protection in windows explorer and it has worked ever since. – johnny Feb 08 '12 at 06:22
  • 5 years on, and with this being a [famous question](https://stackoverflow.com/help/badges/28/famous-question?userid=1115545), would you like to accept an answer? – aaron Dec 19 '17 at 03:49

8 Answers8

288

Since you are learning Git, know that this has little to do with git but with the text editor configured for use. In vim, you can press i to start entering text and save by pressing esc and :wq and enter, this will commit with the message you typed. In your current state, to just come out without committing, you can do :q instead of the :wq as mentioned above.

Alternatively, you can just do git commit -m '<message>' instead of having git open the editor to type the message.

Note that you can also change the editor and use something you are comfortable with ( like notepad) - How can I set up an editor to work with Git on Windows?

Community
  • 1
  • 1
manojlds
  • 275,671
  • 58
  • 453
  • 409
  • I recommend setting the editor to your favorite editor. Then use the command line version (git commit -m '...') when it fits, or let it launch your editor (TextMate, Notepad, whatever) when it doesn't – Gal Aug 26 '15 at 00:18
  • 2
    esc then :wq and enter, great – Suhail Mumtaz Awan Jan 18 '17 at 09:23
81

There is a default text editor that will be used when Git needs you to type in a message. By default, Git uses your system’s default editor, which is generally Vi or Vim. In your case, it is Vim that Git has chosen. See How do I make Git use the editor of my choice for commits? for details of how to choose another editor. Meanwhile...

You'll want to enter a message before you leave Vim:

O

...will start a new line for you to type in.

To exit (g)Vim type:

EscZZ or Esc:wqReturn.

It's worth getting to know Vim, as you can use it for editing text on almost any platform. I recommend the Vim Tutor, I used it many years ago and have never looked back (barely a day goes by when I don't use Vim).

Community
  • 1
  • 1
johnsyweb
  • 129,524
  • 23
  • 177
  • 239
  • 1
    It's hard to see whether the 'O' is upper or lower case. A lower case 'o' causes the message to be written on the second row. – johnny Feb 07 '12 at 09:33
  • I guess it depends on your font. Hopefully the document to which it's hyperlinked will help disambiguate. – johnsyweb Feb 07 '12 at 11:53
  • It's worth getting to know vim so you can quit it from a wide variety of applications that default to it. – djechlin Sep 16 '17 at 21:35
59

That's the vi editor. Try ESC :q!.

A.R.SEIF
  • 761
  • 1
  • 5
  • 22
J-16 SDiZ
  • 25,723
  • 3
  • 63
  • 83
17

On Windows 10 this worked for me for VIM and VI using git bash

"Esc" + ":wq!"

or

"Esc" + ":q!"
atazmin
  • 3,144
  • 1
  • 22
  • 12
14

On windows I used the following command

:wq

and it aborts the previous commit because of the empty commit message

Mayank Pandeyz
  • 24,624
  • 3
  • 35
  • 55
Riya Abraham
  • 151
  • 1
  • 6
8

First type

 i

to enter the commit message then press ESC then type

 :wq

to save the commit message and to quit. Or type

 :q!

to quit without saving the message.

0

On windows, simply pressing 'q' on the keyboard quits this screen. I got it when I was reading help using '!help' or simply 'help' and 'enter', from the DOS prompt.

Happy Coding :-)

Abhinav Saxena
  • 1,940
  • 2
  • 26
  • 54
-1

try

:wq

it works for both windows 10 and windows 11

gongool
  • 1
  • 1