Aborting commit due to empty commit message

匿名 (未验证) 提交于 2019-12-03 01:58:03

问题:

As a newbie git user, when I try to commit my work with

git commit -a -v 

and I enter a commit message in my editor, I close the file, and get this error:

Aborting commit due to empty commit message. 

I have read nearly all the topics addressing to this issue, changed editors, basically tried everything but nothing helps. What should I do?

One thing I noticed, while trying the whole process with notepad++, the file couldn't be saved.

A possible workaround is this:

git commit -am "SomeComment" 

But by doing so I feel I am kind of nullifying the purpose of using git. I want to properly document my changes.

回答1:

When you set an editor in the configuration of Git, make sure to pass the parameter "-w" to force Git to wait your commit message that you would type on your custom editor.

git config --global core.editor "[your editor] -w" 


回答2:

This error can happen if your commit comment is a single line starting with a # character. For example, I got this error when I ended up with the following in my commit message text editor window:

#122143980 - My commit message was here. The number to the left is a Pivotal Tracker story/ticket number that I was attempting to reference in the commit message. # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch [MYBRANCH] # Your branch is up-to-date with 'origin/[MYBRANCH]'. # # Changes to be committed: #   modified:   [MYFILE1] #   modified:   [MYFILE2] # 

The problem, of course, is that my commit message started with a # character, so git saw that line as a comment, and consequently saw the commit message as being empty, as it had nothing but comments!

The fix was to start my commit message with a character other than #.

In my specific case, enclosing the Pivotal ID in square brackets made both git and Pivotal happy:

[#122143980] My commit message here.  


回答3:

If you want to commit with a proper (long, multi-line comment) documentation, but don't want the -m option, what you can do (and that I do when preparing my commits) is to:

  • write your documentation (while you are making the changes) in a separate file 'doc-commit' (or whatever name you want to call it)
  • commit with a 'git commit -a -F /path/to/doc-commit')

In short, use a separate file (which can be at any path you want) as your commit message.



回答4:

I was having this problem. I just installed 1.8.0 earlier, and I found I had to modify the above slightly. I'm very much new at all of this, but essentially it seems that, when committing, it'll use content.editor, not core.editor, at least if you have something set for content.editor.

So, it was

git config --global content.editor "pico -w" 

that finally let me commit! Obviously, of course, use whatever editor you use.

Hope this helps somebody someday!



回答5:

The git does not allows commit without message specified. Have you specified the commit message in commit dialog?

Note that the lines starting with # are treated as comment by Git and are not considered as comments and ignored by Git.



回答6:

I'm also a newbie in Git. I encountered basically the same problem as yours. I solved this by typing:

git commit -a -m 'some message' 

The reason is that git doesn't allow commit without messages. You have to associate some messages with your commit command.



回答7:

I have configured my atom editor as

git config --global core.editor "atom --wait" 

but when I did

git commit 

when atom was already launched, it opened a new tab for adding comments, but git wasn't waiting for me to save file and throwed "Aborting" message instantly. When I closed atom and tried to commit one more time, git launched atom and waited for comments to be added.



回答8:

On windows machine for 'Sublime' editor we can also add the following line in .gitconfig file in the following folder [YOUR DRIVE LETTER]:/users/username/

[core]   editor = '[YOUR DRIVE LETTER]:/Program Files/Sublime Text [YOUR VERSION NUMBER]/sublime_text.exe' --wait 

Hope it helps.



回答9:

For Visual studio Code

git config --global core.editor "code -w" 

For atom

git config --global core.editor "atom -w" 

For sublime

git config --global core.editor "subl -w" 


回答10:

First remove old entries of editors:

git config --global --unset-all core.editor git config  --unset-all core.editor 

Set your editor:

  • For Notepad++

    git config --global core.editor "Notepad++ -w" git config core.editor "Notepad++ -w" 
  • For sublime

    git config --global core.editor "Notepad++ -w" git config core.editor "subl -w" 


回答11:

Make sure to sure a capital W.

git config --global core.editor "open -a 'Sublime Text 2' -W"

or use the following command to replace an existing one that isn't working properly.

git config --replace-all core.editor "open -a 'Sublime Text 2' -W"



回答12:

For commenting on Notepad++ (Windows) do this:

1. Create a batch file somewhere (e.g. c:\Users\me\scripts\npp.bat)
Write this in the batch file (depending on where your Notepad++ is installed):

"C:\Program Files\Notepad++\notepad++.exe" -multiInst -notabbar -nosession -noPlugin "$*" 

2. Save the batch file.
3. Open .gitconfig (which is usually in your Windows User folder) and make sure that
under [core] section you have:

editor = '"c:\\Users\\me\\scripts\\npp.bat"' 

Or either run:

git config --global core.editor '"c:\Users\me\scripts\npp.bat"' 

4. Now perform commit of some kind, and it will open Notepad++, git commit will now wait until notepad++ window is closed.



回答13:

I fixed the problem by switching from my fancy MacVim editor which opens a new window, to the standard default vim in /user/bin/vim which opens in the same window as the shell from whence it is called, and that seems to have fixed the problem.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!