1

I am using git version 2.16.2 on macOS Mojave (but I've seen this on other versions too) and I am observing a strange behaviour of git commit -v.

Sometimes when I write my commit message and close the editor (nano in my case) the commit message gets changed and the commit diff is added to the message.

For example:

commit c7f28bc4849318a542fe6312444f3a72d82787f0
Author: Ivan Dokov <***@gmail.com>
Date:   Tue Oct 16 16:33:49 2018 +0300

Firm Notes deletion

diff --git a/src/app/pages/firm/firm-notes/firm-notes.component.html b/src/app/pages/firm/firm-notes/firm-notes.component.html
index 2267393..f0cfed4 100644
--- a/src/app/pages/firm/firm-notes/firm-notes.component.html
+++ b/src/app/pages/firm/firm-notes/firm-notes.component.html
@@ -14,17 +14,38 @@
...

I think it happens when I do not leave an empty line before:

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.

This behaviour is not consistent. Usually I do not leave an empty line and it works as it should but when I actually see the bad commit message I amend the commit and add an empty line and the issue is resolved. The problem is that I do not always keep an eye on the commit message after I make the commit and I push such bad commit messages to the repository.

Unfortunately I am the only one using git commit -v in the office and nobody else is observing such an issue.

Here is my gitconfig.

Google also is not helping as I cannot seem to find any posts with similar issues.

Update: I just found out that adding an empty line after my commit message is not always solving the issue.

1
  • I had the same error and it broke Gitlab (error 500, unable to load the commit message). I use exact same tools, did you solve your issue?
    – qdequippe
    Apr 10, 2020 at 9:37

2 Answers 2

0

When I do git commit -v I get this message by default:

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Changes to be committed:
#   modified:   foo.txt
#
# ------------------------ >8 ------------------------
# Do not modify or remove the line above.
# Everything below it will be ignored.
diff --git a/foo.txt b/foo.txt
index 88545b8..9fcffaf 100644

For your case this is the part you should not modify:

# ------------------------ >8 ------------------------
# Do not modify or remove the line above.
# Everything below it will be ignored.

When you don't see these lines you might have configured git commit in a strange way. In that case check with this command and consult git help config and git help commit:

git config -l |grep "^commit\."
5
  • I do see the lines and of course I do not modify them. All I do is write the commit message at the top where my cursor is and save the file, but the content of the commit diff is appended to the commit message when I do not leave an empty line after my message.
    – Ivan Dokov
    Oct 22, 2018 at 13:54
  • The magic lines seems to be quite "sensible" - even adding a whitespace triggers the behaviour you observe. So perhaps in YOUR case it is a change in EOL style (LF vs. CR+LF).
    – A.H.
    Oct 22, 2018 at 20:09
  • It is probably the case indeed. Do you think this is related to nano, the terminal (iTerm2) or anything else from the macOS and any clues how to debug and change the behaviour?
    – Ivan Dokov
    Oct 23, 2018 at 9:19
  • I just found out that adding an empty line after my commit message is not always solving the issue.
    – Ivan Dokov
    Oct 23, 2018 at 15:05
  • The commit message is usually stored in .git/COMMIT_EDITMSG. You can compare hexdumps before and after you save the message but before you quit the editor. You could even automate that by wrapping the editor with a shell script which does that job
    – A.H.
    Oct 24, 2018 at 19:55
0

I had the same issue. Turns out my nano editor was configured to write out to DOS format.

When saving the commit, I changed the format using option + m to change it back to the normal format. This stopped the commit message from containing the entire diff.

I must have accidentally set the config to DOS format at some point.

1
  • To be honest this could be the case with me too but I no longer have this issue and I do not remember how it was resolved. Maybe I did OS reinstall for other reasons and the issue somehow disappeared.
    – Ivan Dokov
    Feb 18, 2021 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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