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

cng*_*suz 69 git

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

git commit -a -v
Run Code Online (Sandbox Code Playgroud)

我在编辑器中输入提交消息,我关闭文件,并收到此错误:

Aborting commit due to empty commit message.
Run Code Online (Sandbox Code Playgroud)

我已经阅读了几乎所有涉及这个问题的主题,改变了编辑,基本上尝试了一切,但没有任何帮助.我该怎么办?

有一点我注意到,在使用notepad ++尝试整个过程时,无法保存文件.

一个可能的解决方法是:

git commit -am "SomeComment"
Run Code Online (Sandbox Code Playgroud)

但通过这样做,我觉得我有点无效使用git的目的.我想正确记录我的更改.

小智 115

在Git配置中设置编辑器时,请确保传递参数"-w"以强制Git等待您在自定义编辑器上键入的提交消息.

git config --global core.editor "[your editor] -w"
Run Code Online (Sandbox Code Playgroud)

  • 为我固定,我使用sublime作为编辑器.谢谢. (6认同)
  • 对于macvim,使用`mvim -f`而不是`-w`标志. (5认同)

Jon*_*der 32

如果您的提交注释是以#字符开头的单行,则会发生此错误.例如,当我在提交消息文本编辑器窗口中结束以下内容时,我收到此错误:

#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]
#
Run Code Online (Sandbox Code Playgroud)

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

修复是用除了以外的字符开始我的提交消息#.

在我的特定情况下,将Pivotal ID括在方括号中使得git和Pivotal都很高兴:

[#122143980] My commit message here. 
Run Code Online (Sandbox Code Playgroud)

  • GitLab具有相同的语法语法,我习惯使用问题标识符为我的提交消息添加前缀,这是一个问题,问题编号的包围也适用于GitLab. (2认同)
  • 嗯,很棒,你钉了它!这让我感到很沮丧,但我看到我确实已经开始使用GitHub问题编号`#xxxx已修复:...`并将其更改为`固定#xxxx:...`确实修复了它.谢谢. (2认同)
  • 我通过使用“#123 some message”引用了 github 问题。在提交期间有效,但后来通过编辑器提交“rebase”时失败。 (2认同)

Arm*_*min 12

对于Visual Studio Code

git config --global core.editor "code -w"
Run Code Online (Sandbox Code Playgroud)

对于原子

git config --global core.editor "atom -w"
Run Code Online (Sandbox Code Playgroud)

对于崇高

git config --global core.editor "subl -w"
Run Code Online (Sandbox Code Playgroud)

  • 可能想检查前两种方法之间的区别 (2认同)

Von*_*onC 8

如果你想提交一个适当的(长,多行注释)文档,但不想要这个-m选项,你可以做什么(以及我在准备我的提交时所做的)是:

  • 单独的文件'doc-commit'(或者你想要称之为的任何名称)中编写你的文档(当你进行更改时)
  • 提交' git commit -a -F /path/to/doc-commit')

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


Not*_*ore 6

我也是Git的新手.我遇到了和你一样的问题.我输入以下内容解决了这个

git commit -a -m 'some message'
Run Code Online (Sandbox Code Playgroud)

原因是git不允许在没有消息的情况下进行提交.您必须将某些消息与commit命令相关联.


fiz*_*ris 6

首先删除编辑器的旧条目:

git config --global --unset-all core.editor
git config  --unset-all core.editor
Run Code Online (Sandbox Code Playgroud)

设置你的编辑器:


小智 5

我遇到了这个问题.我刚刚安装了1.8.0,我发现我不得不稍微修改上面的内容.我对这一切都非常新,但基本上看来,在提交时,它将使用content.editor,而不是core.editor,至少如果你为content.editor设置了一些东西.

所以,它是

git config --global content.editor "pico -w"
Run Code Online (Sandbox Code Playgroud)

最后让我承诺!显然,当然,使用你使用的任何编辑器.

希望有一天这会帮助某人!


小智 5

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

请注意,以#开头的行被Git视为注释,不被视为注释而被Git忽略.