Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conventions: write good commit messages #339

Merged
merged 1 commit into from
Apr 3, 2019
Merged

Conversation

smola
Copy link
Contributor

@smola smola commented Mar 26, 2019

Add section on writing good commit and pull request messages.
We should be mindful with other developers and users and document changes properly: what and why something changed.

@smola smola requested a review from a team March 26, 2019 10:40
@smola smola requested a review from mcuadros as a code owner March 26, 2019 10:40
Add section on writing good commit and pull request messages.
We should be mindful with other developers and users and document
changes properly: what and why something changed.

Signed-off-by: Santiago M. Mola <[email protected]>
@smola
Copy link
Contributor Author

smola commented Mar 26, 2019

Fun fact: I initially opened this PR with an empty description ;-)

@smola smola requested a review from a team March 26, 2019 10:42
Copy link
Contributor

@dpordomingo dpordomingo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm but I'd like to know if we have any preference about PR desc or commit message

@@ -30,6 +30,17 @@ Each repository should belong to a team, and the full team has admin rights over
* A maintainer can merge his own PRs without code review, but it is encouraged to ask for a review Merging without review, if done, should be reserved to fixing typos or minor maintenance tasks.
* If a maintainer is missing, the Lead of the team that the project is owned by, or a backup maintainer designated by him will act as maintainer.

## Commit messages

Commit and Pull Request descriptions should be clear and detailed. Keep in mind that commit messages will be read by (eventually) a lot of people:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any preference about both (PR desc vs commit message)?

I use to put most of the effort on explaining the change in the PR description because it is easy to link other issues, commits... create examples, headings...
...and less in commit messages (in my case, they're almost a phrase using imperative tense to describe the change to apply)

I know that PR descriptions can be lost if the repository is migrated, or forked, or moved to bitbucket... and commit messages are forever... so, should we focus much more on commit message? or can we rely on GitHub PRs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(eventually) a lot of people:

and processed by 🤖

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my view, both are very important. Each commit in the PR should document the change made by that particular commit, and the PR overall should document why these commits are together.

Because the scope of individual commits and PRs is often quite different, the level of detail might vary. However, I would generally argue that they should have a similar structure:

  1. A one line synopsis of what the commit/PR accomplishes

  2. A more detailed explanation of why and what is being changed.

For tiny commits it may be OK to omit (2), particularly if it's updates from a code review. But even then there can be value—for example:

Updates from code review.

Fix spelling and punctuation errors, and reformat C files with clang-format.

I find the hardest thing about writing good, clear commit and PR descriptions is getting out of the present moment, where I know as much as I will ever know about this particular issue—and putting myself in the future, when someone else will have to reconstruct it. There is no simple formula for that, obviously—what I try to do is anticipate the questions someone is likely to ask me and answer them up front. YMMV.

Most (all?) of our projects seem to prefer not squashing PRs when they are merged to master. I'd argue that it's therefore important that even our little code-review commits speak for themselves. In a repo where commits are expected to be squashed (even if not ahead-of-time), the PR description and the merge commit can basically be the same description.

Either way, though, the general advice proposed in this PR seems good.

Copy link
Contributor

@kuba-- kuba-- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's independent PR then good description is required. Generally it's good to have informative description, but I really miss a good description in issues. If I have a good description in issue then it's easier to start and I can add it to PR as a reference (instead of copy paste).
So, the good PR's description is description how it was implemented instead of what is the problem about. Problem should be described in referenced issue.
Last but not least - hint for reviewers - it's good to read descriptions, as well.

@smola
Copy link
Contributor Author

smola commented Mar 26, 2019

@kuba-- I really miss a good description in issues.

I agree that we also need far more effort in proper issue descriptions. But an issue description does not replace commit or pull request message. If the issue is properly written, then it can serve as much more detailed context as well as related discussion. The pull request/commit still benefits from a problem statement though.

the good PR's description is description how it was implemented

What and why still apply. What did you do to solve an issue and how? Why it was solved in a certain way and not in a different way? Even with well-defined issues, the exact scope of a given change, rationale of the "how", caveats, and so on, are not necessarily present in the issue in a concise way.

Copy link
Contributor

@bzz bzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smola @creachadair @kuba-- what may also be helpful here is to include some links to a good examples, illustrating the principles from the text. Would you be able to include 2-3 reference examples in here?

@creachadair
Copy link
Contributor

@smola @creachadair @kuba-- what may also be helpful here is to include some links to a good examples, illustrating the principles from the text. Would you be able to include 2-3 reference examples in here?

On Kythe we used to link people to https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html, and I think it's a good balance.

A lot of descriptions get into details about whether you should or shouldn't punctuate and capitalize, rules for tags, etc. I think most of that is a waste of time unless you plan to enforce the rules with presubmits: What we mainly want (I claim) is a low-friction set of simple guidelines that will help us do better.

Here's the canonical example from Tim's post:

Capitalized, short (50 chars or less) summary

More detailed explanatory text, if necessary.  Wrap it to about 72
characters or so.  In some contexts, the first line is treated as the
subject of an email and the rest of the text as the body.  The blank
line separating the summary from the body is critical (unless you omit
the body entirely); tools like rebase can get confused if you run the
two together.

Write your commit message in the imperative: "Fix bug" and not "Fixed bug"
or "Fixes bug."  This convention matches up with commit messages generated
by commands like git merge and git revert.

Further paragraphs come after blank lines.

- Bullet points are okay, too

- Typically a hyphen or asterisk is used for the bullet, followed by a
  single space, with blank lines in between, but conventions vary here

- Use a hanging indent

@smola
Copy link
Contributor Author

smola commented Mar 29, 2019

@bzz Would you be able to include 2-3 reference examples in here?

I'm thinking about commits like this:

These are just a couple of examples I found quickly. I'm not sure about setting "canonical" examples. Sometimes it's great to explain a lot of detail, sometimes it's overkill (but doesn't hurt either).

I didn't include conventions on formatting, which I think it would be better to discuss separately, since I predict much more bikeshedding there (e.g. capitalization yes or no, package prefixes yes or no), although there are some basics:

  • one-line short summary, then blank line, then longer description
  • if relevant, prefix with package name: (e.g. in Go)
  • don't add a dot at the end of the short summary

@creachadair
Copy link
Contributor

  • don't add a dot at the end of the short summary

I wouldn't bother with this constraint unless it serves some tooling purpose. The other two seem good.

@smola
Copy link
Contributor Author

smola commented Apr 3, 2019

Merging, deferred both the discussion on formatting and automation to another issue: #348

@smola smola merged commit 8ffddf8 into master Apr 3, 2019
@smola smola deleted the good-commit-messages branch April 3, 2019 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.