4

My commit messages on git usually look like the following:

* Fix bug abc
* Refactor xyz
* Document 123
* ...

I'm wondering whether this is a bad practice and I should prefer one-line commit messages or at least provide a header line.

On the other hand, this would be less comfortable to write ...

What are your recommendations?

phd
  • 82,685
  • 13
  • 120
  • 165
KnorxThieus
  • 567
  • 8
  • 17
  • 3
    Here is what Linus Torvalds (the creator of git) [thinks a good commit message looks like](https://github.com/torvalds/subsurface-for-dirk/blob/a48494d2fbed58c751e9b7e8fbff88582f9b2d02/README#L88) – Cup of Java Apr 03 '19 at 14:32
  • 3
    The separation of a single line as subject, followed by a blank line and then a description, if necessary, is widely considered good practice. In addition to the link @CupofJava provided [this post](https://chris.beams.io/posts/git-commit/) is a good guideline. – kowsky Apr 03 '19 at 14:39
  • 1
    In many repository viewers (for example, `gitk`) this will show the commit as `* Fix bug abc`. Decide for yourself if this is desirable. But: Considering this example, there really should be three commits, not one. – mkrieger1 Apr 03 '19 at 15:30
  • Thanks for the note! Is there also any rational (technological) reason for leaving empty lines and so on instead of using bullet star points? – KnorxThieus Apr 03 '19 at 16:27
  • it depends greatly on how your team wants to work, and how the people can see the commit messages. Also, most project management tools (Jira, Trello, Azure DevOps, Tuleap, etc...) provide a way to link the commit message with the actual commit by indicating your "ticket/item/artifact/Product backlog item/task" like this @1234 – Pac0 Apr 03 '19 at 18:32

1 Answers1

12

Git standard (even though you can do as you please) is:

  • single line with a brief summary of the change
  • empty line
  • All the gory details in multiple lines
eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • I never noticed about this empty line recommandation but you're right. I guess it's more or less impactful depending on your habits and workflow, but good to enforce anyway. – Romain Valeri Apr 03 '19 at 17:38
  • 2
    For context, empty line convention comes from git itself. For example git commit -m "foo" -m "bar" will result in 3 lines. – Shinebayar G Mar 29 '23 at 18:45