Home > OS >  "Please enter a commit message for your changes"
"Please enter a commit message for your changes"

Time:07-17

enter image description here

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?

CodePudding user response:

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.

CodePudding user response:

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.

  • Related