9.1. Why are commit messages important?
When you commit a change in Git, Subversion, or another version control system (VCS), you’re prompted to write some text describing the commit — a commit message.
How important is this commit message? Should you spend some significant effort writing it? Does it really matter if you write simply fixed a bug?
Most projects have more than one developer and last for some length of time.
Commit messages are a very important method of communicating with other developers, in the present and for the future.
FreeBSD has hundreds of active developers and hundreds of thousands of commits spanning decades of history.
Over that time the developer community has learned how valuable good commit messages are; sometimes these are hard-learned lessons.
Commit messages serve at least three purposes:
Communicating with other developers
FreeBSD commits generate email to various mailing lists.
These include the commit message along with a copy of the patch itself.
Commit messages are also viewed through commands like git log.
These serve to make other developers aware of changes that are ongoing; that other developer may want to test the change, may have an interest in the topic and will want to review in more detail, or may have their own projects underway that would benefit from interaction.
Making Changes Discoverable
In a large project with a long history it may be difficult to find changes of interest when investigating an issue or change in behaviour.
Verbose, detailed commit messages allow searches for changes that might be relevant.
For example, git log --since 1year --grep 'USB timeout'.
Providing historical documentation
Commit messages serve to document changes for future developers, perhaps years or decades later.
This future developer may even be you, the original author.
A change that seems obvious today may be decidedly not so much later on.
The git blame command annotates each line of a source file with the change (hash and subject line) that brought it in.
Having established the importance, here are elements of a good FreeBSD commit message:
As well as including an informative message with each commit, some additional information may be needed.
This information consists of one or more lines containing the key word or phrase, a colon, tabs for formatting, and then the additional information.
For key words where multiple values make sense (e.g., PR: with a comma-separated list of PRs), it is permitted to use the same keyword multiple times to avoid ambiguity or improve readability.
The key words or phrases are:
PR:
The problem report (if any) which is affected (typically, by being closed) by this commit. Multiple PRs may be specified on one line, separated by commas or spaces.
Reported by:
The name and e-mail address of the person that reported the issue; for developers, just the username on the FreeBSD cluster.
Typically used when there is no PR, for example if the issue was reported on
a mailing list.
Submitted by:
(deprecated)
This has been deprecated with git; submitted patches should have the author set by using git commit --author with a full name and valid email.
Reviewed by:
The name and e-mail address of the person or people that reviewed the change; for developers, just the username on the FreeBSD cluster. If a patch was submitted to a mailing list for review, and the review was favorable, then just include the list name. If the reviewer is not a member of the project, provide the name, email, and if ports an external role like maintainer:
Reviewed by a ports maintainer that is not a developer:
Reviewed by: Full Name <valid@email> (maintainer)
Tested by:
The name and e-mail address of the person or people that tested the change; for developers, just the username on the FreeBSD cluster.
Discussed with:
The name and e-mail address of the person or people that contributed to the patch by providing meaningful feedback; for developers, just the username on the FreeBSD cluster.
Typically used to credit those who did not explicitly review, test, or approve the change, but nevertheless contributed to the discussion surrounding the change, which led to improvements and a better understanding of its impact on the FreeBSD project.
Approved by:
The name and e-mail address of the person or people that approved the change; for developers, just the username on the FreeBSD cluster.
There are several cases where approval is customary:
while a new committer is under mentorship
commits to an area of the tree covered by the LOCKS file (src)
during a release cycle
committing to a repo where you do not hold a commit bit (e.g. src committer committing to docs)
committing to a port maintained by someone else
While under mentorship, get mentor approval before the commit. Enter the mentor’s username in this field, and note that they are a mentor:
Approved by: username-of-mentor (mentor)
If a team approved these commits then include the team name followed by the username of the approver in parentheses. For example:
Approved by: re (username)
Obtained from:
The name of the project (if any) from which the code was obtained. Do not use this line for the name of an individual person.
Fixes:
The Git short hash and the title line of a commit that is fixed by this change as returned by git log -n 1 --pretty=format:'%h ("%s")' GIT-COMMIT-HASH.
We include the commit title so that the referenced commit can be located even in the case that a future VCS migration invalidates hash references.
MFC after:
To receive an e-mail reminder to MFC at a later date, specify the number of days, weeks, or months after which an MFC is planned.
MFC to:
If the commit should be merged to a subset of stable branches, specify the branch names.
MFH:
If the commit is to be merged into a ports quarterly branch name, specify the quarterly branch. For example 2021Q2.
Relnotes:
If the change is a candidate for inclusion in the release notes for the next release from the branch, set to yes.
Candidates are user-visible changes, new features, compatibility breaks, etc..
If you forget to set this line, or want to provide more details, add an entry to the RELNOTES file in the root of the src tree.
The RELNOTES file is used to generate release notes for the next release.
Do not use the Relnotes: line to describe the change: its only valid value is yes.
Security:
If the change is related to a security vulnerability or security exposure, include one or more references or a description of the issue. If possible, include a VuXML URL or a CVE ID.
Event:
The description for the event where this commit was made. If this is a recurring event, add the year or even the month to it. For example, this could be FooBSDcon 2019. The idea behind this line is to put recognition to conferences, gatherings, and other types of meetups and to show that these are useful to have. Please do not use the Sponsored by: line for this as that is meant for organizations sponsoring certain features or developers working on them.
Sponsored by:
Sponsoring organizations for this change, if any. Separate multiple organizations with commas. If only a portion of the work was sponsored, or different amounts of sponsorship were provided to different authors, please give appropriate credit in parentheses after each sponsor name. For example, Example.com (alice, code refactoring), Wormulon (bob), Momcorp (cindy) shows that Alice was sponsored by Example.com to do code refactoring, while Wormulon sponsored Bob’s work and Momcorp sponsored Cindy’s work. Other authors were either not sponsored or chose not to list sponsorship.
Pull Request:
This change was submitted as a pull request or merge request against one of FreeBSD’s public read-only Git repositories.
It should include the entire URL to the pull request, as these often act as code reviews for the code.
For example: https://github.com/freebsd/freebsd-src/pull/745
Example 4. Commit Log for a Commit Based on a PR
The commit is based on a patch from a PR submitted by John Smith.
The commit message "PR" field is filled.
Example 5. Commit Log for a Commit Needing Review
The virtual memory system is being changed.
After posting patches to the appropriate mailing list (in this case, freebsd-arch) and the changes have been approved.
Example 6. Commit Log for a Commit Needing Approval
Commit a port, after working with the listed MAINTAINER, who said to go ahead and commit.
...
Approved by: abc (maintainer)
Where abc is the account name of the person who approved.
Example 7. Commit Log for a Commit Bringing in Code from OpenBSD
Committing some code based on work done in the OpenBSD project.
...
Obtained from: OpenBSD
Example 8. Commit Log for a Change to FreeBSD-CURRENT with a Planned Commit to FreeBSD-STABLE to Follow at a Later Date.
Committing some code which will be merged from FreeBSD-CURRENT into the FreeBSD-STABLE branch after two weeks.
Where 2 is the number of days, weeks, or months after which an MFC is planned. The weeks option may be day, days, week, weeks, month, months.
It is often necessary to combine these.
Consider the situation where a user has submitted a PR containing code from the NetBSD project.
Looking at the PR, the developer sees it is not an area of the tree they normally work in, so they have the change reviewed by the arch mailing list.
Since the change is complex, the developer opts to MFC after one month to allow adequate testing.
The extra information to include in the commit would look something like
Example 9. Example Combined Commit Log
PR: 54321
Reviewed by: -arch
Obtained from: NetBSD
MFC after: 1 month
Relnotes: yes