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

Community
  • 1
  • 1
kajaco
  • 2,547
  • 3
  • 24
  • 33
  • 1
    Does it work with `core.editor = vim`? – alternative Sep 21 '10 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 '10 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'`. – Chris Johnsen Sep 24 '10 at 08: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 '10 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. – Phil Miller Sep 24 '10 at 16:34

5 Answers5

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"
CB Bailey
  • 755,051
  • 104
  • 632
  • 656
  • 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 '10 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 '10 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 '10 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 '10 at 21:27
  • I changed the user.editor and the core.editor. I did another commit and used just `:w` first. The status bar indicated the file was written. Then I did `:q`, but got the same "empty" message. – kajaco Sep 21 '10 at 21:46
  • @meador: I **DO** get that message immediately. However, I get it even after making the corrections indicated. – kajaco Sep 21 '10 at 21:47
  • @kajaco: What do you mean by user.editor? Also, what is the returned when you run `git config core.editor`? – CB Bailey Sep 21 '10 at 21:50
  • @Charles Bailey: user.editor is set in .gitconfig. See Edit2 in the question for the other answer. (Don't know /want to take time to learn right now how to put break lines into a comment, and it's unintelligible without them.) – kajaco Sep 21 '10 at 21:55
  • @kajaco: `user.editor` is not a valid git config setting, you need to have a single value for your `core.editor` setting. Please see my edit. – CB Bailey Sep 21 '10 at 22:00
  • @Charles Bailey: Should I delete the user.editor line from the .gitconfig file? It's still there after doing your edit regarding git config. (user.editor was set up during installation of git, iirc.) – kajaco Sep 21 '10 at 22:08
  • It shouldn't be doing any harm, it's just not used AFAIK. – CB Bailey Sep 21 '10 at 22:15
  • @Charles Bailey: git config core.editor now gives "gvim -f". However, when I try to do a commit, I *still* immediately get the "Aborting commit due to empty commit message" line. See Edit 3. – kajaco Sep 23 '10 at 16:53
  • 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 '10 at 17:05
  • @kajaco: I don't know what to suggest. I can say that I have verified and do get the behaviour that you are seeing when I set `core.editor` to `gvim` but that `git commit` works correctly when I set it to `gvim -f`. There's obviously something wrong in your environment. Perhaps you could give more details about it and go step by step into exactly what you do and type and what error and other messages you see. – CB Bailey Sep 23 '10 at 19:08
  • This fix worked for me, too, using MacVim (`mvim -f`). Thanks! – Bodhi Mar 29 '12 at 23:05
  • Since vi is an alias for vim on my machine (as it is on most), I have vim as an alias for gvim. I was having trouble with this so I tried setting core.editor to vim, gvim, vim -f, gvim -f, and vi. None worked. I use :x by default, and saw an answer here recommending it instead of :wq so I thought I'd try :wq instead. No joy. Then, on a hunch, I tried `git commit` instead of `git commit -v` ( which I would prefer ) and it works with vi, vim -f, and gvim -f. – bsoist Mar 05 '14 at 16:16
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.

Maxy-B
  • 2,772
  • 1
  • 25
  • 33
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.

Brian Campbell
  • 322,767
  • 57
  • 360
  • 340
0

Consider using the fugitive git plugin for vim.

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

Roland Smith
  • 42,427
  • 3
  • 64
  • 94
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.

CCoder
  • 2,305
  • 19
  • 41
japaniel
  • 160
  • 5