Gerrit/Commit message guidelines

The commit message of your change plays an important role.

It is first thing other people will see about your change.

Subject
The first line of the commit message is known as the subject.

The subject should be less than 80 characters long (aim for 50-70).


 * Summarize your change in the subject line. Keep in mind that this will be in the repository forever.


 * Use the imperative mood in your subject line. The imperative mood sounds like you are giving instructions to someone, it could start with words like "Change", "Add", "Fix", "Remove", "Update", "Refactor", or "Document".  Good examples are "Add Badge::query for querying the API" or "Allow zeroes in SimpleBadge::add".  Bad examples would be "Added Badge::query method" or "Fixed Badge::query method", or "Badge can query the API" and "Zeroes work when adding badges".


 * Do not end the subject line with a period (dot).


 * Optionally, prefix the subject with the relevant 1>#Component|component. A component is the general area that your commit will change.

Body
When writing the body text, think about the following questions:


 * Why should this change should be made? What is wrong with the current code?


 * Why should it be changed in this way? Are there other ways?


 * Did you consider other approaches? If so, describe why they were not as good.


 * How can a reviewer test or verify that your code is working correctly?

Do:


 * Separate the body from the subject with one empty line.


 * Wrap the message body so that lines are less than 100 characters long. But, do not break or wrap URLs, keep them even if they are longer.


 * Format "Bug" and "Change-Id" meta-data exactly like in the examples below, and place them together at the end of the body, after one empty line.


 * Refer to other (merged) commits by using a (short) Git commit hash. If necessary, refer to not-yet-merged commits by using a Gerrit Change-Id.

Don't:


 * Do not refer to other commits with a Gerrit URL, instead use the Git commit hash. This allows easy navigation of the Git repository when offline.  It also allows users of all repository viewers (Gerrit, Gitiles, Phabricator, GitHub, and local Git interfaces) to automatically navigate to other commits within the same interface.  A URL can only be resolved when online and using Gerrit, which breaks the ability for people to navigate quickly.


 * Do not use a URL as the only explanation for a change. If the change is justified by discussions elsewhere or external documentation, then briefly summarise the relevant points in the commit message.

Good example
jquery.badge: Add ability to display the number zero

Cupcake ipsum dolor sit. Amet tart cheesecake tiramisu chocolate cake topping. Icing ice cream sweet roll. Biscuit dragée toffee wypas.

Does not yet address T44834 or T176. Follow-up to Id5e7cbb1.

Bug: T42 Change-Id: I88c5f819c42d9fe1468be6b2cf74413d7d6d6907

Bad example
Improved the code by fixing a bug.

Changed the files a.php and b.php

Bug: T42 Change-Id: I88c5f819c42d9fe1468be6b2cf74413d7d6d6907

Subject
Most programs we use that display Git commit, render the subject line as plain text.

This means URLs do not work, and selecting/copying of text often is not possible.

Therefore, do not mention Phabricator tasks, Git commits, or urls inside the subject line.

Instead, mention those in the body text, or footer meta-data.

That way, they can be universally selected, copied, or clicked.


 * Gerrit uses the subject in: email notifications, IRC notifications, 1>gerrit:#/q/project:mediawiki/core+branch:master+is:merged,n,z|search results.


 * GitHub uses the subject in: [https://github.com/wikimedia/mediawiki-core/commits/ commit history], [https://github.com/wikimedia/mediawiki-core/commit/a943d0da14f1ff4435409171a32f03cb958025ad commit subject].


 * The Git CLI uses the subject in:,  ,  ,  , etc.


 * and much more!

Component
You may start the subject line with a component, which will indicate what area of the project is changed by your commit.

It should be one of the following:


 * A directory of PHP classes under   or  , such as <tvar|3>"installer", "jobqueue", "objectcache", "resourceloader", "rdbms"</>, etc.


 * A PHP class name, such as <tvar|1>"Title", "User", "OutputPage"</>, etc.; typically for classes without subdirectory in <tvar|2> </>.


 * ResourceLoader module name (like <tvar|1>"mediawiki.Title", "mediawiki.util"</>, etc.).


 * Generic keyword affecting multiple areas relating to the type of change, such as:
 * "build" - for changes to files relating to the development workflow, such as updates to <tvar|1>, </>, etc.
 * "tests", "qunit", "phpunit" - for changes that only affect unit or integration test suites, or the test suite runners.

Phabricator
To reference a <tvar|1></> bug or task, in the commit message mention it inline using the <tvar|2>Txxx</> notation (e.g. "<tvar|3> That was caused by T169. </>")

To express that a commit resolves (even partially) or is specially relevant to a bug, add <tvar|1> </> in the footer at the end of the commit message.

(If you're amending a commit message, insert it immediately above the <tvar|1> </> line, without an empty line between them.)

Bug: T169

A bot will automatically leave a comment on the Phabricator task about any significant events (being merged, abandoned, etc.).

If a patch resolves two or more bugs, put each <tvar|1> </> reference on its own line at the bottom.

Cross-references
Whenever you refer to another commit, use the SHA-1 git hash of the merged commit.

If the commit in still pending review, use the Gerrit Change-Id hash instead of the git hash because the hash relates to an individual patch set (which changes when rebased, thus creating a dead-end).

Change-Id
<tvar|1></>'s <tvar|2> </> tool will automatically append the "<tvar|3>Change-Id: Ixxx</>" keyword to new commits.

Dependencies
If you have 1>Special:MyLanguage/Gerrit/Cross-repo dependencies</>|cross-repo dependencies (your commit depends on another commit in a different repository), declare them by adding <tvar|2> </> to the last paragraph.

("<tvar|1>Ixxx</>"... is the <tvar|2> </> of the other commit.)

This will instruct Zuul to test the commit together with that one.