git 由于空提交消息而中止提交

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9725160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:13:01  来源:igfitidea点击:

Aborting commit due to empty commit message

git

提问by cngkaygusuz

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

作为一个新手 git 用户,当我尝试提交我的工作时

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.

我注意到的一件事是,在使用 notepad++ 尝试整个过程时,无法保存文件。

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.

但是通过这样做,我觉得我在某种程度上否定了使用 git 的目的。我想正确记录我的更改。

回答by Zakaria AMARIFI

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 的配置中设置编辑器时,请确保传递参数“-w”以强制 Git 等待您将在自定义编辑器上键入的提交消息。

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

回答by Jon Schneider

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!

当然,问题在于我的提交消息以#字符开头,因此 git 将该行视为注释,因此将提交消息视为空的,因为它只有注释!

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 Pivotalhappy:

在我的特定情况下,将 Pivotal ID 括在方括号中使git 和Pivotal 都满意:

[#122143980] My commit message here. 

回答by Armin

For Visual studio Code

对于 Visual Studio 代码

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"

回答by VonC

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

如果您想使用适当的(长的多行注释)文档提交,但不想要该-m选项,您可以做的(以及我在准备提交时所做的)是:

  • 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')
  • 单独的文件“doc-commit”(或任何您想调用的名称)中编写您的文档(在您进行更改时)
  • 用“ 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.

简而言之,使用单独的文件(可以位于您想要的任何路径)作为提交消息。

回答by Nothing More

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

我也是 Git 的新手。我遇到了和你基本一样的问题。我通过输入解决了这个问题:

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.

原因是 git 不允许提交没有消息。您必须将一些消息与您的提交命令相关联。

回答by salix

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.

我遇到了这个问题。之前我刚安装了1.8.0,发现上面要稍微修改一下。我对这一切都很陌生,但基本上似乎在提交时,它将使用 content.editor,而不是 core.editor,至少如果您为 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!

希望有一天这对某人有所帮助!

回答by Yin

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

git 不允许在没有指定消息的情况下提交。您是否在提交对话框中指定了提交消息?

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

请注意,以 # 开头的行被 Git 视为注释,不会被视为注释并被 Git 忽略。

回答by Anmol Saraf

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

在用于“Sublime”编辑器的 Windows 机器上,我们还可以在以下文件夹中的.gitconfig文件中添加以下行[YOUR DRIVE LETTER]:/users/username/

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

Hope it helps.

希望能帮助到你。

回答by Pavel Tsybulivskyi

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.

当 atom 已经启动时,它打开了一个新选项卡来添加评论,但 git 没有等我保存文件并立即抛出“中止”消息。当我关闭 atom 并尝试再提交一次时,git 启动 atom 并等待添加评论。

回答by fizcris

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"
    
  • 对于记事本++

    git config --global core.editor "Notepad++ -w"
    git config core.editor "Notepad++ -w"
    
  • 为了崇高

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