Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

This window drives me crazy

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.

It pops up when I forget to put -m"[message]" after "git commit", and now when I'm experiment with "git revert" I've seen instructions on how to abort this, but what if I actually want to submit a commit message? How do I do that? Pressing enter doesn't work, so what does?

This isn't Git at the moment. Without -m, Git opens a text editor of your choice for you to compose the commit message. Once you have saved the file and exited the editor, Git uses the contents of that file as the commit message. – chepner Jul 17, 2022 at 13:58 Well, which editor did you choose to have Git use? (If you didn't choose one, perhaps you should.) – torek Jul 17, 2022 at 13:59 This is not specific to git. Its a vi editor that git opens up for you by default for you to be able to type in commt message. So basically when you get to this screen, just get into insert mode by hiting INSERT key on your keyboard, and then type in your message. ONce done, you are good to save and exit and you do this with hitting ESC key and then typing in :wq. You can change the default editor to some editor of your choice. If you wish to use VScOde, then type this in git terminal git config --global core.editor 'code' – Asif Kamran Malick Jul 17, 2022 at 14:01

The first line before

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.

is precisely there for adding your commit message.

You press i, and you enter insert mode. You can navigate around the text and insert what ever you want. When done, press Esc. This makes you exit insert mode. Next you have to press :wq, which means to write and quit.

This will save your commit message.

Git allows you to use an editor of your choice to enter a commit message. If you don't specify one, then the default editor is a system-specific default, usually vi, which is a modal editor coming from Unix. As the Git FAQ says:

If you haven’t specified an editor specifically for Git, it will by default use the editor you’ve configured using the VISUAL or EDITOR environment variables, or if neither is specified, the system default (which is usually vi). Since some people find vi difficult to use or prefer a different editor, it may be desirable to change the editor used.

(When I wrote this, it was rather tongue-in-cheek, since a great many people do find vi difficult to use because the editing paradigm differs from most other editors. “How to quit vim” is a common search topic.)

My recommendation here is to type Esc and then :wq (then Enter) to quit vi and then configure the editor of your choice instead using the core.editor option. The Git FAQ provides examples of how to do this properly. Once you've done that, you can attempt your commit or revert again.

If you don't have a preferred editor, nano is a relatively simple editor that I can recommend for this case. I don't believe it's shipped with Git for Windows, though, so you'll need to download it separately.

If you do want to learn to use vi, then I'd recommend the vimtutor program, which comes with Vim (which is the most common vi editor and the option shipped with Git for Windows) that will teach you how to use it properly.

Your git is configured to use vi as a text editor (it is also the editor you will get if nothing else is defined).

You can change this editor to something else, for example :

  • you can use Notepad++ :
  • git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
    
  • or Visual Studio Code :
  • git config --global core.editor "code --wait"
    
  • or any text editor you like : just check the command line options you have to pass to your editor
  • Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.