News for hackers. Stuff that matters.
Re:Linus Torvalds: 'I Do No Coding Any More' by systemvoltage on Sunday July 05, 2020 @02:50PM (#23740930)
Commit messages are supposed to be short. "Fixed stuff" is totally wrong. I usually write "Added ability to do foo with bar when baz is true."

Commit messages aren't mutually exclusive to the inline documentation.

I am making the case that inline documentation is far more important than commit messages.

Re:Linus Torvalds: 'I Do No Coding Any More' by xorcist on Sunday July 05, 2020 @04:57PM (#23741909)
"Supposed" to?

Git was made with the intention that commit messages look like whole emails, describing not only why the change was made but also the thought process behind it, why this particular solution was chosen instead of some other etc.

What you describe is a decent header, although most people would probably prefer "Add ability to" (not "Added ability to", this is a custom that goes way back before git).

Inline documentation, or comments, is something else entirely. That is a moving target that can describe intended usage, remote APIs, and hard to understand passages. Commit messages describes a particular changeset, at a fixed point in time.

Google it, and see that most people's ideas of a good commit message goes way beyond the header ("shortlog") line.

Re:Linus Torvalds: 'I Do No Coding Any More' by alphachloride on Monday July 06, 2020 @12:28AM (#23744691)
Could be selection bias. People who comment about good commit messages are most likely people who pay attention to commit messages. That does not necessarily mean they make up a majority of committers.
Re:Linus Torvalds: 'I Do No Coding Any More' by alexchantavy on Monday July 06, 2020 @12:20AM (#23744657)
GitHub discourages making commit messages longer than a certain number of characters; it’s interesting for me to see other opinions on that.
Re:Linus Torvalds: 'I Do No Coding Any More' by andersonvom on Monday July 06, 2020 @12:27AM (#23744690)
You're talking about the title of the commit message. Yes, the title is supposed to be under 50 characters. Now add a blank line after it and you can write all you want (line wrap at 72 chars).

If you use markdown Syntax in your commit body, github and other tools will gladly render it correctly. You can grep for commit messages with "git log --grep <pattern>" and it will also search commit bodies as well. It's beautiful!

Re:Linus Torvalds: 'I Do No Coding Any More' by smichel17 on Wednesday July 08, 2020 @06:26AM (#23768563)
Adding on to sibling comment, on GitHub the additional lines they're talking about go in the box before the commit title.
Re:Linus Torvalds: 'I Do No Coding Any More' by jkaplowitz on Sunday July 05, 2020 @03:22PM (#23741154)
There's no general rule about what length a commit message should be, except that often people try to keep the first paragraph as a single short line for better readability in systems like GitHub and the git CLI.

When additional detail is helpful about the motivation for or gotchas related to a commit, starting a new paragraph and elaborating there is totally fine.

But I agree with you, they aren't mutually exclusive to inline documentation. The inline documentation is more important when the explanation is relevant to understanding the code which results from the commit, whereas a clear commit message is more important when the information is to illuminate the reasons for (or history surrounding) the change itself.

Re:Linus Torvalds: 'I Do No Coding Any More' by systemvoltage on Sunday July 05, 2020 @03:31PM (#23741217)
Agree with all you've said. Commit messages do serve a slightly different purpose of historical context.
Re:Linus Torvalds: 'I Do No Coding Any More' by cwsx on Sunday July 05, 2020 @04:29PM (#23741659)
I was taught by a previous manager always to follow: `add/update/remove/fix {feature/bug} by/with {reason} ({further explanation if required})`

This also follows what I've seen at a few companies since then. Would you say that's a general rule?

Re:Linus Torvalds: 'I Do No Coding Any More' by MaxBarraclough on Sunday July 05, 2020 @04:48PM (#23741833)
There's now an effort to (loosely) standardise this convention: https://www.conventionalcommits.org/en/v1.0.0/#summary
Re:Linus Torvalds: 'I Do No Coding Any More' by jkaplowitz on Sunday July 05, 2020 @05:18PM (#23742089)
Ah! That seems slightly different from the format the person you're replying to described, but I have seen this version in use at one job.

There was only used by one person who gave no context on why he used that format, so it's probably no coincidence in such an example that to me the extra structure seemed to add only opacity and no real value.

I can absolutely imagine that being different in a company that used this convention widely and built tooling around it. Doubly so when a lot of the staff is junior enough that it's helpful guidance for structuring thoughts around what the commit does.

Re:Linus Torvalds: 'I Do No Coding Any More' by jkaplowitz on Sunday July 05, 2020 @05:08PM (#23742001)
I've never seen that anywhere I've worked, though it's a readable enough format that it wouldn't bother me if someone decided to adopt it for a good reason like compatibility with parsing by dev workflow dashboards or other automatic tooling.

Though, I'm not sure it's a helpful restriction for commits that clarify, refactor, or clean up code. One can certainly reference an issue tracker number as the {feature/bug} element that gives the necessary context, but the strictness spreads the information around more widely than is natural.

If someone was adopting that convention as a workaround for helping team members learn how to communicate, they're probably going to find that it's a very incomplete workaround.

Re:Linus Torvalds: 'I Do No Coding Any More' by cwsx on Sunday July 05, 2020 @09:21PM (#23743780)
I should note this is normally done on a feature branch (with the ticket number attached). i.e. feature/{ticket-#}-{ticket-title}

When merging you can pretty easily see what ticket each commit was for. Seems superfluous to put the same information in every commit messages.

Re:Linus Torvalds: 'I Do No Coding Any More' by jkaplowitz on Monday July 06, 2020 @02:46AM (#23745326)
Thanks for the clarity. Yeah, I agree it would be unhelpfully repetitive if every commit in a given feature branch merge has nearly basically the same title. That's not best practice anywhere I've worked.

By contrast, referencing the ticket number (but not necessarily ticket title) is common practice in the PR message, and seems much more helpful.

Re:Linus Torvalds: 'I Do No Coding Any More' by mcv on Sunday July 05, 2020 @05:52PM (#23742405)
Commit messages and code comments serve different purposes. The commit message should be about what you changed, so they help you find the interesting commit from a list of commit messages, whereas comments in the code should be about why the code is the way it is. Is it because of a bug in a library? Is it arbitrary? A quick fix that still has some debt? Did someone waste a lot of time on this?

Commit messages are about the change, whereas comments are about the state of the code.