tags:

views:

238

answers:

2
+3  Q: 

Git commit fails

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

+1  A: 

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
I am not doing this.
kajaco
+14  A: 

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"
Charles Bailey
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
+1 Yeah, this is it, I think.
mathepic
@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?
Charles Bailey
I'm not sure I said "saving my message doesn't work."
kajaco
@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?
Charles Bailey
@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
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
@meador: I **DO** get that message immediately. However, I get it even after making the corrections indicated.
kajaco
@kajaco: What do you mean by user.editor? Also, what is the returned when you run `git config core.editor`?
Charles Bailey
@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
@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.
Charles Bailey
@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
It shouldn't be doing any harm, it's just not used AFAIK.
Charles Bailey
@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
@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
@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.
Charles Bailey