Aborting commit due to empty commit message
GitGit Problem Overview
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.
Git Solutions
Solution 1 - Git
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"
Solution 2 - Git
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.
Solution 3 - Git
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"
Solution 4 - Git
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.
Solution 5 - Git
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.
Solution 6 - Git
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"
Solution 7 - Git
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!
Solution 8 - Git
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.
Solution 9 - Git
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.
Solution 10 - Git
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.
Solution 11 - Git
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.
Solution 12 - Git
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!
Solution 13 - Git
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.
Solution 14 - Git
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.
Solution 15 - Git
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"
Solution 16 - Git
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"
Solution 17 - Git
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.
Solution 18 - Git
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
Solution 19 - Git
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.
Solution 20 - Git
solution for commit error
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.
Solution 21 - Git
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
.
Solution 22 - Git
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.
Solution 23 - Git
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)
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.
Solution 24 - Git
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.
Solution 25 - Git
-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.