Version control

Commit discipline

We follow the Git project's own commit discipline practice of "Each commit is a minimal coherent idea". This discipline takes a bit of work, but it makes it much easier for code reviewers to spot bugs, and makes the commit history a much more useful resource for developers trying to understand why the code works the way it does, which also helps a lot in preventing bugs.

Commits must be coherent:

Commits should generally be minimal:

When not to be overly minimal:

Other considerations:

Zulip expects you to structure the commits in your pull requests to form a clean history before we will merge them. It's best to write your commits following these guidelines in the first place, but if you don't, you can always fix your history using git rebase -i (more on that here).

Never mix multiple changes together in a single commit, but it's great to include several related changes, each in their own commit, in a single pull request. If you notice an issue that is only somewhat related to what you were working on, but you feel that it's too minor to create a dedicated pull request, feel free to append it as an additional commit in the pull request for your main project (that commit should have a clear explanation of the bug in its commit message). This way, the bug gets fixed, but this independent change is highlighted for reviewers. Or just create a dedicated pull request for it. Whatever you do, don't squash unrelated changes together in a single commit; the reviewer will ask you to split the changes out into their own commits.

It can take some practice to get used to writing your commits with a clean history so that you don't spend much time doing interactive rebases. For example, often you'll start adding a feature, and discover you need to do a refactoring partway through writing the feature. When that happens, we recommend you stash your partial feature, do the refactoring, commit it, and then unstash and finish implementing your feature.

Commit messages

First, check out these examples of commits with good commit messages.

The first line of the commit message is the summary. The summary: * is written in the imperative (e.g., "Fix ...", "Add ...") * is kept short (max 76 characters, ideally less), while concisely explaining what the commit does * is clear about what part of the code is affected -- often by prefixing with the name of the subsystem and a colon, like "zjsunit: ..." or "docs: ..." * is a complete sentence.

Good summaries:

Below is an example of a good commit summary line. It starts with the prefix "provision:", using lowercase "p". Next, "Improve performance of install npm." starts with a capital "I", uses imperative tense, and ends with a period.

provision: Improve performance of installing npm.

Here are some more positive examples:

channel: Discard all HTTP responses while reloading.

integrations: Add GitLab integration.

typeahead: Convert to ES6 module.

tests: Compile Handlebars templates with source maps.

blueslip: Add feature to time common operations.

gather_subscriptions: Fix exception handling bad input.

Compare "gather_subscriptions: Fix exception handling bad input." with:

The summary is followed by a blank line, and then the body of the commit message.

Tip: You can set up Zulip's Git pre-commit hook to automatically catch common mistakes in the commit message itself.

Message body: