Live data from Hacker News

What a good commit message looks like (2011)

github.com

31–40 of 100 posts

Re: What a good commit message looks like (2011)

#31
post #28
post #23

Earlier quoted context omitted.

Highly disagree. As long as the code lives, the commit lives.

until the git killer comes along and the team decides how much history they are willing to migrate. I've seen it happen every 5(?) years across several companies. Ironically it's always the oldest commit messages that turn out to be the most valuable because newer changes people remember

What is "The Git Killer"?

Re: What a good commit message looks like (2011)

#32
post #27
post #17

The body of the commit message can be several paragraphs, and please do proper word-wrap and keep columns shorter than about 74 characters or so. That way "git log" will show things nicely even when it's indented. Software should help me, I shouldn't have to help it. Why doesn't git handle this formatting automatically? I shouldn't need to manually break lines for typographical (not paragraph) reasons.

That software is called a text editor and you can configure it to do the text wrapping for you. More seriously, it is quite hard to wrap text correctly after you submitted it. For example people add manual line breaks for structuring text and to separate things like quoted commands from the rest. It would be much more cumbersome to go back after a git commit to fix this, probably in multiple iterations until you get…

Web browsers line break text dynamically just fine - as do, well, text editors.

Using a text editor to automatically embed line breaks doesn't fix the problem: embedding line breaks in text for formatting is wrong semantically. Hard line breaks should mean something. Now I can't reflow the text to display it on a web page in a normal font, because I can't be sure of which line breaks are meaningful, and which are formatting.

Re: What a good commit message looks like (2011)

#33
post #26

Here's what, Tim Pope, our favourite vim nerd has to say about this: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messa... (Same, but with more words.) A point of contention seems to be the choice of the imperative, at least for the subject line. While I'm really used to it, both when reading and writing, many people seem to strongly prefer past tense ("Fixed bug …" instead of "Fix bug …").

With that one, the way I see it is that when people use the past tense, the git history becomes a work log, i.e. what the committer did; "I fixed bug...". It shouldn't be like that, the commit should describe what the commit does, i.e. "Fix bug" or "Fixes bug". the latter uses more letters though, which is probably why I see a preference for the "Fix bug" format due to the (soft) 50 character subject constraint.

Re: What a good commit message looks like (2011)

#34
post #26

Here's what, Tim Pope, our favourite vim nerd has to say about this: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messa... (Same, but with more words.) A point of contention seems to be the choice of the imperative, at least for the subject line. While I'm really used to it, both when reading and writing, many people seem to strongly prefer past tense ("Fixed bug …" instead of "Fix bug …").

Also, when using his amazing git plugin (fugitive) to commit you get very useful highlighting when you break these conventions.

http://i.imgur.com/8ix5JGa.png

Re: What a good commit message looks like (2011)

#35
post #27
post #17

The body of the commit message can be several paragraphs, and please do proper word-wrap and keep columns shorter than about 74 characters or so. That way "git log" will show things nicely even when it's indented. Software should help me, I shouldn't have to help it. Why doesn't git handle this formatting automatically? I shouldn't need to manually break lines for typographical (not paragraph) reasons.

That software is called a text editor and you can configure it to do the text wrapping for you. More seriously, it is quite hard to wrap text correctly after you submitted it. For example people add manual line breaks for structuring text and to separate things like quoted commands from the rest. It would be much more cumbersome to go back after a git commit to fix this, probably in multiple iterations until you get…

[deleted]

Re: What a good commit message looks like (2011)

#36
post #18

Great system about our commit system at work is that every commit starts with the name of a ticket of our ticket system (jira) so you can go back to that ticket whenever that commit comes up anywhere and understand the commit better

even better systems allows to link tickets to commits.

Not the OP, but our JIRA instance does this. From a ticket in JIRA, you can see any commits, branches or pull requests mentioning that ticket.

We also use this convention with gitflow, so our branches are named eg, feature/PROJ-1234-added-new-ui or bug/PROJ-2345-fix-new-ui. This also lets JIRA find and link them, and makes pull requests get the ticket number in their title by default as well (since its based on branch name).

The last bit is just a short human-readable thing to make branches easier to look at and find, because the initial way we started using gitflow:

    feature/
      feature/PROJ-2286
      feature/PROJ-2352
      feature/PROJ-2367
      feature/PROJ-2382
      feature/PROJ-2385
    bug/
      bug/PROJ-2240
      bug/PROJ-2323
      bug/PROJ-2393
is completely unintelligible.

Re: What a good commit message looks like (2011)

#37
post #15
post #8

Recently, I try to write the first line of my commit messages so they describe what the system now does, compared to before the commit. This makes reading the history much more fun. Like: Validation of email addresses now sends a test email to the user, instead of the old regex that never worked. This style does not work for all kinds of changes, but when it works, it creates a nice history of how the functionality o…

Including the old bit is meaningless noise there. I'd use something like "Improve email validation" or "email: send a test email as validation" or such. The body is where you can describe previous behaviour and give more details.

Yeah that. I'd have it describe what the commit does in the subject, and both the why and how in the body:

Validation of email addresses now sends a test email to the user, instead of the old regex that never worked.

> Send test email to user for email address validation > > This change was done because the old regex never worked; see also {link} and {link} for more information.

as an example. Ideally the header also contains a hint to the module the change was done in, etc. The linux kernel commits take this to (what comes across to me as) the highest levels.

Re: What a good commit message looks like (2011)

#38
post #26

Here's what, Tim Pope, our favourite vim nerd has to say about this: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messa... (Same, but with more words.) A point of contention seems to be the choice of the imperative, at least for the subject line. While I'm really used to it, both when reading and writing, many people seem to strongly prefer past tense ("Fixed bug …" instead of "Fix bug …").

More importantly, the correct way is the way that is currently being used.

If the project uses past tense, use it. If you want to change the convention, that's okay too, but everyone has to change.

It's exactly the same issue as coding style. If you can look at code or commit messages and figure out who wrote it based purely on style/formatting, you're doing it wrong (or rather: the person using the inconsistent style/format is).

Re: What a good commit message looks like (2011)

#39
post #17

The body of the commit message can be several paragraphs, and please do proper word-wrap and keep columns shorter than about 74 characters or so. That way "git log" will show things nicely even when it's indented. Software should help me, I shouldn't have to help it. Why doesn't git handle this formatting automatically? I shouldn't need to manually break lines for typographical (not paragraph) reasons.

m-X auto-fill-mode. You can add this to other modes automatically. I almost always have it on.

Added to Emacs in 1977.

Re: What a good commit message looks like (2011)

#40
post #19
post #14

Should be noted, it is often tempting to describe everything about the change in the commit description rather than comments in the code. Remember, git commits disappear from sight pretty soon and become fossils, whereas there may be something important that should be said in the code itself.

I think that on the contrary, everything should be in the commit. The commit message is dated, it has an author and a context. How often do you come across stray comments which shouldn't be here because the code got refactored away? Commis are often just a git blame away anyway.

Except when a line has been changed over a longer period of time. Although maybe I'm just not comfortable with tracking history too much, because in the applications I generally work on (customer-facing webapps) we generally don't need to look back in history too much.
Post reply on HN