The Git project provides guidelines, including how to compose commit messages. When writing a commit message, follow these additional guidelines:
- Add a required tag and optional subtag(s).
- Add a paragraph.
- Add an associated bug.
- Optionally indicate multiple steps.
- Add tests and run them automatically multiple times.
- Add a buffer line before the Change-Id.
- Use Change-Id to refer to related changes
Add required tag
[tag] helps readers of the commit tell what subject your change is
about. The format is simply a keyword between brackets, for example,
keyword has no specific meaning, but should help readers identify the subject
easily. More specific tags or multiple tags can also be used to specify more
fine-grained subjects, for example,
The following example shows required tags in the commit message subject:
[parent][component] Update component in Fuchsia Write the details of a commit message here. Bug: <issue-tracker-ID> Test: Added test X.
You can view the commit history of the files you've edited to check for the tags used previously. See these examples:
Commit message tags are required. If the subject of a commit message
doesn't include tags, Gerrit flags your
Needs Label: Commit-Message-has-tags.
The paragraph underneath the header line describes in better detail what the reason for the change is, and in general brief terms describe what it is intended to do, for example:
[docs] Adding Fuchsia Commit message style guide This change centralizes all commit message style guide into one style guide. It also removes duplicate content from existing pages and points to the new style guide instead. Change-Id: I307e5b24df4273661d22c52c81038de50600c76c
If you want Fuchsia Gerrit to know what issue this change is associated with,
you need to add the
Bug: <issue-tracker-ID> line. To associate multiple issues
with a change, list each bug in a separate line. To link Issue Tracker issues,
prefix your bug id with
b/, for example:
[parent][component] Update component in Fuchsia Write the details of a commit message here. Bug: 82657 Bug: b/179167977 Test: Added test X.
The difference between
Fixed: is that
Fixed: automatically closes
the issue for you once your change is submitted, whereas
Bug: only comments on
your issue once submitted. If you have multiple changes attached to your issue, use
Bug: tag for all the changes up until the final change. Use
the final change, so that the issue is closed.
Indicate multiple steps
When executing a change that requires multiple steps across various repositories (for instance, to soft transition APIs defined in one repository and used in others), indicate multiple steps by referencing the last step taken and the next step taken.
This enables reviewers and those looking at the log to understand and navigate the totality of the change. When possible, it is encouraged to provide all steps to complete the migration in each commit log (but that may be impractical in some cases).
Here's an example of a commit message with multiple steps:
[fidl][go] Support for flexible enums (1/3) Step 1 of 3. Adds support for flexible enums to fidlgen_go: * For all enums, emit `IsUnknown()` method indicating whether the value is unknown (or known). While relevant only for flexible enums, it is possible to construct unknown strict enums using type casts. * Emit an internal method `I_EnumIsStrict` indicating whether the enum is strict or flexible. This method is read by the runtime, when creating enum marshaler. * For flexible enums, we generate a default unknown placeholder Step 2: I1102f244aa5ab4545fab21218c1da90be08604ec Step 3: If0a047a4db804a183e984676217b31e17b4af0ea Test: fx test fidl_go_conformance at If0a047a4db804a183e984676217b31e17b4af0ea Change-Id: Id71eb879e4d7dfabe228cc7b4e2fedb7f52db7b7
Add tests and multiply line
Test: line is necessary to indicate what type of test to run to make sure
your change is working. You can add multiple different tests in this line, for
fx test setui_service_tests, setui_client_interface_test. You can
also add explanations of what tests you added below. If you did not add or
modify tests, you can specify
None:, with an explanation of why it doesn't need
to be tested, for example,
None: documentation change only.
If you added new tests, you can get deflake runs automatically by adding the
Multiply: line with the test to run multiple times.
The following example shows
Multiply: in the commit
[SetUI] Correct internal items' visibility Part II This CL marks some internal items with pub(crate), pub(super) or leaves as private. Related CL: fxr/535942 Bug: 72941 Test: fx test -o setui_service_tests setui_client_interface_test sample-setui-config-test setting-service-config-test Multiply: setui_service_tests Multiply: setui_client_interface_test Change-Id: I67e061edee1e81a6875bf26b752ba5687c4ced71
If the testing instructions are complex, create an issue and provide a link to that issue in the change description. If the change doesn't intend to change behavior, indicate that fact in the commit message.
In some cases, certain behavior changes cannot be tested because Fuchsia lacks some particular piece of infrastructure. If so, create an issue in the tracker about the necessary infrastructure support and provide the bug number in the change description, in addition to describing how the change is tested manually, for example:
Test: Manually tested that [...]. Automated testing needs US-XXXX.
Developers are responsible for high-quality automated testing of their code. Reviewers are responsible for pushing back on changes that do not include sufficient tests. See Fuchsia testability rubrics for more information on how to introduce testable and tested code in the Fuchsia project.
Add a buffer line before Change-Id
The Change-Id gets added automatically when you commit your changes. You may
want to add a buffer line between your other lines and the Change-Id, in case
git commit --amend, so that Gerrit doesn't parse the Change-Id as a
regular line, and add a second ID to it.
For more specific details, see the Git interpret trailer rules.
Use Change-Id to refer to related changes
To reference another Gerrit change in a commit message, always use the Change-Id.
Using the Change-Id is preferred since:
The git SHA is only known after a change is merged, and while guidance could be given to use the Change-Id in one case, and the git SHA in the other, prefer uniform guidance. Furthermore, you cannot reference other repositories using the git SHA.
The link to the change is assigned by Gerrit, and is not part of the persistent history of the repository. Should the review mechanism change, the Change-Id will continue to be part of the recorded history, whereas the change's number will not. There are also rare occurrences where change numbers may be lost, for example, due to re-indexing issues.
For instance, to refer to the change that added
and not the git SHA
or the link to the change,