Search code examples
gitversion-controlgit-commit

Why is it necessary to enter commit messages?


I have been using git for a while now, and I had a question. Why is it necessary to add commit messages when using git commit? I mean, I admit that it is quite useful for me in some cases when I actually want to explain what a specific change does to the project.

But why is it still made necessary to write a commit message? I mean what if I am committing a minor change like fixing a spelling mistake in my UI? Is it a good thing that this is made necessary? or would it be better/worst if this was optional?


Solution

  • If it were optional, users would have the option of omitting it even when they really should be explaining what got changed.

    If it's not optional, users are at worst mildly inconvenienced by having to make up a trivial commit message like "fixed a typo".

    Ideally, you should be able to look at the output of git log --oneline and still get an idea of what changes have been made. Consider this log:

    a2b2c3 Fix another critical error in bar
    abcdef
    123456 Introduce critical method bar
    

    Do you want to assume that abcdef is a minor typo that someone decided wasn't worth a comment, or should you assume that it's a major bug fix implied by the use of "another" in the next commit?


    Strictly speaking, it's not necessary; it's just the default to enforce adding a commit message. You can use git commit --allow-empty-message to proceed without one.