109

As a newbie git user, when I try to commit my work with

git commit -a -v

and I enter a commit message in my editor, I close the file, and get this error:

Aborting commit due to empty commit message.

I have read nearly all the topics addressing to this issue, changed editors, basically tried everything but nothing helps. What should I do?

One thing I noticed, while trying the whole process with notepad++, the file couldn't be saved.

A possible workaround is this:

git commit -am "SomeComment"

But by doing so I feel I am kind of nullifying the purpose of using git. I want to properly document my changes.

6
  • Which version of git for windows are you using?
    – Josh Lee
    Mar 15, 2012 at 18:26
  • 3
    The only nullifying thing here is not inputting a relevant commit message. git commit -am "SomeRelevantComment"
    – NickSuperb
    Mar 15, 2012 at 19:54
  • What error do you get when you try to save the file from your editor? Mar 15, 2012 at 20:47
  • I have had that problem on Windows 7, while working on files that were under `C:\Program Files`. Windows 7 protects against writing in this directory (and anywhere under), and since the temporary file (COMMIT_MSG or something) where you write your commit message is created in the .git directory, that failed.
    – Gauthier
    Mar 11, 2013 at 13:45
  • "documentate"? Hmm...
    – Patrick
    Sep 25, 2015 at 1:57

26 Answers 26

179

When you set an editor in the configuration of Git, make sure to pass the parameter "-w" to force Git to wait your commit message that you would type on your custom editor.

git config --global core.editor "[your editor] -w"
13
  • 1
    Samesies on sublime text 2. Tried a bunch of other stuff, this was first to work. Thanks Zak. Apr 13, 2014 at 0:50
  • 9
    For macvim, use mvim -f instead of the -w flag. Sep 14, 2015 at 6:51
  • 1
    Seems like sometimes there's a bug when you use an existing instance of gedit to set a commit message, so "gedit -w" didnt work for me, but "gedit -s" or "gedit --standalone" works.
    – jfv
    Mar 19, 2016 at 10:35
  • 1
    what exactly does -w do?
    – Blubber
    Sep 1, 2016 at 16:44
  • 1
    Using "code -w" appears to have made it work for me on Windows 10 with Microsoft Code editor.
    – lit
    Mar 30, 2019 at 20:28
73

This error can happen if your commit comment is a single line starting with a # character. For example, I got this error when I ended up with the following in my commit message text editor window:

#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]
#

The problem, of course, is that my commit message started with a # character, so git saw that line as a comment, and consequently saw the commit message as being empty, as it had nothing but comments!

The fix was to start my commit message with a character other than #.

In my specific case, enclosing the Pivotal ID in square brackets made both git and Pivotal happy:

[#122143980] My commit message here. 
4
  • 4
    GitLab has the same syntax for issues, I'm used to prefixing my commit messages with the issue identifier and this was an issue, the bracketing of the issue number works fine with GitLab too.
    – Orbling
    Aug 9, 2017 at 13:56
  • 4
    Huh, wonderful, you nailed it! It was driving me battey but I see I had indeed started the commit with the GitHub issue number #xxxx Fixed: ... and changing this to Fixed #xxxx: ... has indeed fixed it. Thank you. Oct 25, 2017 at 1:36
  • 2
    I had referenced a github issue by using #123 some message. worked during commit, but failed later when commiting the rebase via editor. Oct 15, 2020 at 7:50
  • 1
    I got this when trying to cherry pick a single commit starting with #. Amending the commit message and force-pushing the commit before cherry picking fixed the issue. Apr 21, 2022 at 4:21
30

For Visual studio Code

git config --global core.editor "code -w"

For atom

git config --global core.editor "atom -w"

For sublime

git config --global core.editor "subl -w"
3
  • 2
    Might want to check the difference between your first two methods
    – mcalex
    Aug 6, 2017 at 13:59
  • And how do you go back to the original setting? Or how do you read the current setting?
    – Tim
    Dec 7, 2018 at 14:02
  • Note that you'll need to open a new terminal session for these to take effect. At least for me on MacOS.
    – Stan James
    Dec 12, 2022 at 18:21
13

I'm also a newbie in Git. I encountered basically the same problem as yours. I solved this by typing:

git commit -a -m 'some message'

The reason is that git doesn't allow commit without messages. You have to associate some messages with your commit command.

10

First remove old entries of editors:

git config --global --unset-all core.editor
git config  --unset-all core.editor

Set your editor:

  • For Notepad++

    git config --global core.editor "Notepad++ -w"
    git config core.editor "Notepad++ -w"
    
  • For sublime

    git config --global core.editor "Notepad++ -w"
    git config core.editor "subl -w"
    
9

If you want to commit with a proper (long, multi-line comment) documentation, but don't want the -m option, what you can do (and that I do when preparing my commits) is to:

  • write your documentation (while you are making the changes) in a separate file 'doc-commit' (or whatever name you want to call it)
  • commit with a 'git commit -a -F /path/to/doc-commit')

In short, use a separate file (which can be at any path you want) as your commit message.

3
  • Will I be able to make comments in that file (# my comment)? Feb 4, 2014 at 12:14
  • @Lego I suspect so (haven't tested it directly, but it should take the full content of your text file as a commit message.
    – VonC
    Feb 4, 2014 at 14:02
  • I just tried it out: My comments were treated as part of the message, so it seems that it is not possible to have comments in the text file. Anyway I like the process of documenting changes in a separate doc-commit file while working on a task. So - thanks! Feb 4, 2014 at 14:15
6

I was having this problem. I just installed 1.8.0 earlier, and I found I had to modify the above slightly. I'm very much new at all of this, but essentially it seems that, when committing, it'll use content.editor, not core.editor, at least if you have something set for content.editor.

So, it was

git config --global content.editor "pico -w"

that finally let me commit! Obviously, of course, use whatever editor you use.

Hope this helps somebody someday!

1
  • do you know does the -w stands for? Apr 28, 2022 at 18:14
4

The git does not allows commit without message specified. Have you specified the commit message in commit dialog?

Note that the lines starting with # are treated as comment by Git and are not considered as comments and ignored by Git.

0
4

I have configured my atom editor as

git config --global core.editor "atom --wait"

but when I did

git commit

when atom was already launched, it opened a new tab for adding comments, but git wasn't waiting for me to save file and throwed "Aborting" message instantly. When I closed atom and tried to commit one more time, git launched atom and waited for comments to be added.

1
  • same for "code" git config --global --replace-all core.editor "code --wait"
    – shapkin
    May 24, 2022 at 13:30
4

On windows machine for 'Sublime' editor we can also add the following line in .gitconfig file in the following folder [YOUR DRIVE LETTER]:/users/username/

[core]
  editor = '[YOUR DRIVE LETTER]:/Program Files/Sublime Text [YOUR VERSION NUMBER]/sublime_text.exe' --wait

Hope it helps.

1
  • For me this creates a file called --wait. Do you have a working example where the path to the file includes spaces, as in Program Files? Thanks.
    – zx81
    Nov 15, 2016 at 11:41
4
git config --global core.editor "subl -w" -F 

This helped me after lots and lots of trial and error, hope someone finds it useful.

I had already symlinked sublime 3 to use as subl command.

I am completely clueless, for why -F flag outside the " " worked.

1
  • 1
    I didn't need the -F flag; -w was sufficient. -w tells Sublime to "Wait for the files to be closed before returning" (from subl --help).
    – Galen Long
    Aug 12, 2020 at 21:17
2

It expects a commit message.

For vim: ( I'm a newbie as well. I only worked with vim so far)

After your command,

git commit -v

You will be directed to a file with the name

".git/COMMIT_EDITMSG"

That opens up in your editor (which in my case is vim)

You will find a lot of commented text that looks exactly like what you saw when you did

git status  OR
git diff

If you notice, you can see an empty line on top - where it expects a commit message. You may type the commit message here and save & quit the editor. It's done!

1
  • perfecto !!! I know there would be a simple solution Mar 16, 2020 at 13:34
2

To begin with, make sure your git is correctly configured to open some kind of editor prompt (visual studio / sublime / notepad++ / atom etc) in order to proceed further.

  • For my case I configured my git to use visual studio in Ubuntu environment.
  • I tried committing a change, it failed with given failure.
  • Then I looked at my .gitconfig file and found out my editor was missing -w parameter
  • I ran git config --global core.editor "code -w" command and rechecked my .gitconfig file, noticed the -w was added there correctly.
  • Tried committing the change again and it worked for me.

Hope this helps for some other newbie's like myself.

1

Make sure to sure a capital W.

git config --global core.editor "open -a 'Sublime Text 2' -W"

or use the following command to replace an existing one that isn't working properly.

git config --replace-all core.editor "open -a 'Sublime Text 2' -W"

1

For commenting on Notepad++ (Windows) do this:

1. Create a batch file somewhere (e.g. c:\Users\me\scripts\npp.bat)
Write this in the batch file (depending on where your Notepad++ is installed):

"C:\Program Files\Notepad++\notepad++.exe" -multiInst -notabbar -nosession -noPlugin "$*"

2. Save the batch file.
3. Open .gitconfig (which is usually in your Windows User folder) and make sure that
under [core] section you have:

editor = '"c:\\Users\\me\\scripts\\npp.bat"'

Or either run:

git config --global core.editor '"c:\Users\me\scripts\npp.bat"'

4. Now perform commit of some kind, and it will open Notepad++, git commit will now wait until notepad++ window is closed.

1

I had the same problem with atom but I resolved it by using notepad instead by changing the core editor for git using the following command

git config --global core.editor "C:\\Windows\\notepad.exe"
0

I fixed the problem by switching from my fancy MacVim editor which opens a new window, to the standard default vim in /user/bin/vim which opens in the same window as the shell from whence it is called, and that seems to have fixed the problem.

1
  • 1
    you simply need to add the -f flag e.g. git config --global core.editor "mvim -f" Sep 30, 2016 at 5:25
0

I got this problem, and found out that if I dont put any comment after committing, it gives me that error. If I jump to get back to the main bash straight away, it doesnt commit.Just to be more clear, Im using GIT Bash, not other editor

0

When I used the complete atom filepath it didn't work, so instead of using:

git config --global core.editor "c:/programs/atom/atom.exe -w"

I used:

git config --global core.editor "atom -w"

and it worked just fine. Good luck!

IMPORTANT: First make sure that atom starts correctly calling it directly (atom) from the command line you are using.

0

solution for commit error

enter image description here

As I shown above there is a commit field which you need to enter while committing, this is basically for version control and understanding the changes for each commit.

If you don't enter this you will get the error :Aborting commit due to empty commit message

Note: the above works only in Rstudio commit and pulling the files.

0

I got this error, and even though i used git config --global core.editor "code -w", it still wouldn't wait for me to close the file. It would just abort instantly.

My problem was that I had run this command earlier git config core.editor "code".

It seems that core.editor (which I presume is a local working directory specification), took precedence over --global core.editor.

If git config --global core.editor "code -w" (or whatever editor you are trying to use) does not work for you, try omitting the --global.

0

The reason for your problem is your editor was closed before you enter the commit. I faced the same issue. So telling your editor to wait is the answer for your problem.

You need to change the global variable of core.editor in GIT for that.

Before changing you might wanna see, what is the existing one. Then use below code to see them as a list.

git config --global --list

mine, before core.editor is with no waiting.

core.editor=gedit

Therefore I changed that variable with below two codes. First line for unset the variable and second for declaring it correctly.

git config --global --unset-all core.editor

git config --global core.editor "code -w"

With this, my issue was solved, Hope yours too. If you check the global variables with

git config --global --list

again, you will see your core.editor is changed too, like below.

core.editor=gedit -w

It shows now your "waiting" function is working.

0

I have just encountered this error and just solved it, so I would like to share my scenario and answer as well.

I ran the command git config --global core.editor "\"C:\Program Files (x86)\Notepad++\notepad++.exe\""

and then when I do git commit it opens the notepad++ but after I give my commit message and saves by pressing "ctrl+s", it has shown me this message in command prompt -> "Aborting commit due to empty commit message." (as shown in the below image)

git commit showing error - abort commit due to empty message

I solved it by providing my commit message like below (we need to provide 2 empty lines between our Commit TITLE and commit Description as shown below)

Note: The lines started with "#" are automatically generated by git.

git commit opens editor which can be set by the command git config --global core.editor ""C:\Program Files (x86)\Notepad++\notepad++.exe""

0

After wasting one hour to make it work on my Ubuntu, I decided to use Sublime Text instead of Atom to write my commit messages. So instead of:

git config --global core.editor "atom -w"

I used the same command for Sublime.

git config --global core.editor "subl -w"

And it worked fine. Sublime pause waiting for the commit message.

0

-w as others suggested didn't work for me but --wait did.

Full input is git config --global core.editor 'code --wait'

(code is VS Code, replace with subl for Sublime etc.)

As the full name of the argument makes it obvious, this sets editor for commit message to open (code) and tells it to wait until file is saved and closed.

Don't forget to save the file before closing.

0

I had the same problem, and none of the previous answers here were helpful. Here's what I ended up doing. It's really hacky, but it's guaranteed to work.

  1. Write a bash script (eg git_text_editor.bash) that calls your editor of choice and passes the input argument (ie the file to be opened) to it. Make sure this part works before moving on.
  2. Inside the bash script, after the command that calls the editor, add the following line: read n1
  3. In .gitconfig, set your bash script as the "editor".

What will happen now is, whenever git calls your editor, it won't resume until you've pressed Enter. So, you can write your commit message in your preferred editor, save it, maybe even close it and open it again to make changes because you forgot something -- in other words, whatever you want -- and whenever you think you're ready, you go back to bash and press Enter to finish the commit.

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