Git 提交因 Vim 和 GVim 而失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3764481/
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
Git commit fails with Vim and GVim
提问by kajaco
When I try to do a git commit -a
, I get a nice vim instance. I type in my message, do :wq
, vim closes down and the terminal has the message,
当我尝试执行 a 时git commit -a
,我得到了一个不错的 vim 实例。我输入我的消息, do :wq
,vim 关闭并且终端有消息,
Aborting commit due to empty commit message.
Pursuant to this questionI made sure my core.editor says "gvim" (so does the user.editor, fwiw), but I still get that error message.
根据这个问题,我确保我的 core.editor 说“gvim”(user.editor、fwiw 也是如此),但我仍然收到该错误消息。
Does anyone have another idea?
有没有人有其他想法?
Edit 1: I amable to commit by specifying a file. My messages are too long to reasonably use the -m option.
编辑1:我是能够通过指定一个文件提交。我的消息太长,无法合理使用 -m 选项。
Edit 2:
编辑2:
$ git config core.editor
vim
error: More than one value for the key core.editor: vim
error: More than one value for the key core.editor: gvim
Edit 3:Still having the same problem, even with core.editor sorted. Any other ideas?
编辑 3:仍然有同样的问题,即使 core.editor 排序。还有其他想法吗?
$ git config core.editor
gvim -f
$ git commit
Aborting commit due to empty commit message.
Edit 4:Other error messages. This is everything I'm seeing. I excluded several from my original question because I've gotten them on many machines, none of which had problems using vim/gvim with git (except the current one). In the case shown here, core.editor is set to vim -f
.
编辑 4:其他错误消息。这就是我所看到的一切。我从最初的问题中排除了几个,因为我已经在许多机器上得到了它们,其中没有一个在使用 vim/gvim 和 git 时遇到问题(当前的除外)。在此处显示的情况下,core.editor 设置为vim -f
。
$ git commit
(gvim:21655): GLib-WARNING **: g_set_prgname() called multiple times
** (gvim:21655): CRITICAL **: gtk_form_set_static_gravity: assertion `static_gravity_supported' failed
** (gvim:21655): CRITICAL **: gtk_form_set_static_gravity: assertion `static_gravity_supported' failed
** (gvim:21655): CRITICAL **: gtk_form_set_static_gravity: assertion `static_gravity_supported' failed
** (gvim:21655): CRITICAL **: gtk_form_set_static_gravity: assertion `static_gravity_supported' failed
** (gvim:21655): CRITICAL **: gtk_form_set_static_gravity: assertion `static_gravity_supported' failed
Aborting commit due to empty commit message.
When core.editor is set to gvim -f
I get exactly the same error messages except the number is 21641, not 21655. When I Google one of the lines, I get no matches (I find that hard to believe, but there you are).
当 core.editor 设置gvim -f
为时,除了数字是 21641,而不是 21655 之外, 我得到完全相同的错误消息。当我搜索其中一行时,我没有得到匹配项(我觉得这很难相信,但你就是这样)。
回答by CB Bailey
If you are using gvim, you need to make sure that it stays in the foreground, otherwise it will return control to git before you've had a chance to edit and save your message. Specifying the -f
switch as part of the editor setting should enable this.
如果您正在使用 gvim,您需要确保它保持在前台,否则它会在您有机会编辑和保存消息之前将控制权返回给 git。将-f
开关指定为编辑器设置的一部分应启用此功能。
gvim -f
You have multiple values set for your core.editor
setting which is causing a problem. You need to have just one setting.
您core.editor
为导致问题的设置设置了多个值。您只需进行一项设置。
Try:
尝试:
git config --global --unset-all core.editor
git config --unset-all core.editor
git config --global core.editor "gvim -f"
回答by Maxy-B
Using gvim -f
should be the solution (works for me), but simply setting core.editor
may not necessarily cause git to use it. To find out what git is actuallyusing, run git var GIT_EDITOR
. It should print gvim -f
. If not, check man git-var
and jump to the section on the GIT_EDITOR
variable to find out what could be overriding your core.editor
setting.
使用gvim -f
应该是解决方案(对我core.editor
有用),但简单的设置不一定会导致 git 使用它。要找出 git实际使用的内容,请运行git var GIT_EDITOR
. 它应该打印gvim -f
. 如果没有,请检查man git-var
并跳转到有关GIT_EDITOR
变量的部分以找出可能覆盖您的core.editor
设置的内容。
回答by Brian Campbell
Are you prefixing the lines in your commit message with #
? If you are, Git will treat those as comment lines, ignore them, and find no content in your message.
您是否在提交消息中添加了前缀#
?如果是,Git 会将它们视为注释行,忽略它们,并且在您的消息中找不到任何内容。
回答by japaniel
I had come across a similar error.
我遇到过类似的错误。
Running a :wq
or :q!
would exit with issues. I have tried other editors (TextMate) and upon save and exit of that editor, the commit would complete.
运行:wq
or:q!
会出现问题。我尝试过其他编辑器 (TextMate),在该编辑器保存和退出后,提交将完成。
Found that when closing the document with :x
the commit would close without having to move to gvim and all the configuration that was needed there.
发现使用:x
提交关闭文档时将关闭而无需移动到 gvim 和那里需要的所有配置。
Summary -
概括 -
:x
was my answer.
:x
是我的回答。