Created: 2021-01-03

Git commit messages and the misconception of non-existent space

Most git commit messages that I've seen are just very short.
Also I do sometimes write commit messages that aren't very good. Sometimes I just put a single dot as commit message, which I do in git repos of mine where I don't need a message for myself, but only for git.

But there are many cases where I want to write good messages and describe things properly.

Due to the git commit command vim got opened and I just started to write my message.
My head filled with things that I wanted to communicate and then after writing just a few word suddenly the foreground color changed: At the beginning it was yellow but then it became white. I thought "Ok, perhaps a text-width issue" and hit enter and continued in the next line, where the background color was suddenly red and the forground color white!! I was shocked, hit <esc> to enter normal mode and fired up :q! to leave.
"Why is it not allowed to write more?" - I thought. I mean, why should it be allowed since "all" the commit messages out there are so short - for sure it's something forbidden. I don't want to break anything, so I have to learn how to describe things properly with just very few words. But wait... how many? "Lets check this again" and opened vim again with the result of 51 characters. 51! Wow ok. Many people out there say: "Write good commit messages". Well, I've heard that so many times, but this is in fact a very hard task to manage within only 50 characters - 51 if I don't use a closing dot.

And so I started to messages like:

"Typo; Simpler loop; Added comments"

I did this with -m on command line because for such short messages I didn't want to open my editor. After a while I realised that it's allowed to use the -m option multiple times and I did so. But the "problem" was that each message provided with -m appeared in a separate paragraph. I wasn't satisfied by all this. I like git a lot but not being able to write longer commit messages... "damn"... So I started to play around and tried things like breaking lines with trailing backslashes. I tried many many weird stuff and once I just realised, that it is also possible to do it this way:

git commit -m'
Started my commit message in this line and typed and
typed and typed. And I wrote more text and even more
and after just writing a lot of things down that were
all in my head and that I wanted to be there, I thought
that I might try out to end with the first logical
part in here' -m'
and to write another logical part into a separate
paragraph. And I was really excited what will happen
if' -m'
I just hit enter after typing all this text'

and I did so and magically nothing got broken!! LOL :-D
Also my git log showed a very nice result and I was just fascinated and happy that I was wrong all the time.

Of course the next (logical) question was:
Why does my editor colorize the text that way? Am I still missing something? It turned out: yes, I am :-) I just stumbled upon this stackoverflow thread where they link to the original explanation of

"As a general rule, your messages should start with a single line that’s no more than about 50 characters and that describes the changeset concisely, followed by a blank line, followed by a more detailed explanation."

For example - one of my online contacts told me that - git log --oneline displays the first line of commits. To be honest, I don't understand, why vim is doing such a huge warning disco highlighting to just warn people about that. From my perspective really too much and misunderstandable - but of course I could have done some better research on the git topic itself :-)

But I'm very happy that I know this and from now I'll gonna use vim again for my longer commit messages. This is one of those cases where I was glad to be wrong.