34

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,

Aborting commit due to empty commit message.

Pursuant to this question I made sure my core.editor says "gvim" (so does the user.editor, fwiw), but I still get that error message.

Does anyone have another idea?

Edit 1: I am able to commit by specifying a file. My messages are too long to reasonably use the -m option.

Edit 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?

$ 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.

$ 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).

5
  • 1
    Does it work with core.editor = vim? Sep 21, 2010 at 21:12
  • @mathepic: No. And it makes new vars, all called core.editor, with the various choices. How do I get rid of the extras? That's surely going to cause problems.
    – kajaco
    Sep 21, 2010 at 21:51
  • 1
    Re: your “Edit 3”. It looks like you might have an extra newline in the value for core.editor (there should not be a blank line between gvim -f and the next prompt unless your shell’s prompt is putting it there). If the gvim-started-by-committing does not present you with a commit template (usually a single blank line followed many informational “# comment” lines) then this could be part of the problem. Remove the extra newline from the value; reset the value taking care not to press Return/Enter before the closing quote in git config --global core.editor 'gvim -f'. Sep 24, 2010 at 8:18
  • @Chris Johnsen: good eye. Don't think that's the problem though; it was a result of the copy/paste I did as I was removing irrelevant stuff from my command prompt. Double-checked just now and there wasn't a blank line after the gvim -f line, just another prompt.
    – kajaco
    Sep 24, 2010 at 14:42
  • The 21641 and 21655 that you see are process IDs. They are unlikely to appear identically in search results. Just leave those numbers out. Sep 24, 2010 at 16:34

5 Answers 5

76

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 -f

You have multiple values set for your core.editor setting which is causing a problem. You need to have just one setting.

Try:

git config --global --unset-all core.editor
git config --unset-all core.editor
git config --global core.editor "gvim -f"
16
  • I did say that I was able to input my commit message. Gvim pops up and I start typing. Are you saying I cannot focus on any other window until I am done with the commit message?
    – kajaco
    Sep 21, 2010 at 21:15
  • @kajaco: You also say that saving your message doesn't work which would be explained by gvim's auto-detaching-from-the-shell behaviour. Are you saying that this fix doesn't work for definite?
    – CB Bailey
    Sep 21, 2010 at 21:17
  • @kajaco: Well, you posted an error message saying that the commit message was empty when git read it so evidently you git didn't read the message that you tried to save. Again: are you saying that this fix doesn't work for definite?
    – CB Bailey
    Sep 21, 2010 at 21:26
  • 1
    @kajaco: if this answer is correct, you'll see the "Aborting commit due to empty commit message." in the shell immediately when gvim pops up. Try it again and switch back to the terminal window as soon as gvim opens (before putting in your commit message or saving) to look for the error.
    – rmeador
    Sep 21, 2010 at 21:27
  • 1
    @kajaco: “I DO get that message immediately.” – Exactly. When you do a commit, git launches the editor and waits for it to return and then tries does the commit. The problem you have is that gvim is a graphical editor and launches in the background (of the console). So the console call gvim immediately returns and git uses the (unchanged by that time) commit message file. Then you get the focus of the vim window, and change the file. But at that time, git's job is already done. So you need to make the gvim call not return before you close the window. And -f does exactly that.
    – poke
    Sep 23, 2010 at 17:05
6

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 actually using, 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.

4

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.

1
  • Yep, that was my case. Thank you Brian!
    – zuba
    Sep 10, 2012 at 18:32
0

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.

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.

Summary -

:x was my answer.

0

Consider using the fugitive git plugin for vim.

You can perform the most often-used git command straight from (g)vim.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.