Aborting commit due to empty commit message

后端 未结 20 1937
[愿得一人]
[愿得一人] 2020-12-04 09:45

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 g

相关标签:
20条回答
  • 2020-12-04 09:54

    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"
    
    0 讨论(0)
  • 2020-12-04 09:55

    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. 
    
    0 讨论(0)
  • 2020-12-04 09:57

    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"
      
    0 讨论(0)
  • 2020-12-04 09:58

    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.

    0 讨论(0)
  • 2020-12-04 09:58

    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.

    0 讨论(0)
  • 2020-12-04 09:58

    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.

    0 讨论(0)
提交回复
热议问题