Bitwise’s convention on how to structure, write, and use commit messages

Standards and Practices for Bitwise Industries

Bitwise’s convention on how to structure, write, and use commit messages

Using a convention for commit messages has several benefits. For one, it makes it easier to find individual commits. It also forces us to keep our commits small enough to be able easily reason what they’re doing. And lastly to be able to revert small chunks of code if needed.

Git Commit Messages Conventions

There are many conventions available, many follow a close resemblance to the Conventional Commits specification.

👍 The one we use at Bitwise is based on the Karma Runner project. Please review it.

Guidelines:

Format

Your commit messages should be formatted as follows:

Short message example (git commit -m "..."):

type(scope):subject

Long message example (git commit):

type(scope):subject
(blank line)
body

type: Select one of the following 8 commit types. These are your only options for commit type:

scope: Narrow the scope of the commit to a one or two word description in parentheses

subject: Favor imperative mood, present tense, active voice, and start with verbs. Don’t use a period at the end. Think of it as a newspaper headline.

body (optional): If necessary, provide additional context that can help other developers in the future. This is normally unnecessary but some use cases are:

Examples

Say you have changed four files:

app.component.ts app.router.ts login.component.ts login.component.scss

There are at least two scopes being dealt with here: the app.component scope and the login.component scope.

Automation Tools 🛠

There are many tools available to help you enforce the commit convention rules via git hooks. This way you can always be sure that your commit will satisfy the rules before they’re added to the history.

One example, if you’re using npm/package.json in your project, you can install commitlint package. This adds a commit message linter to your command line. There are many plugins available for it with pre-configured convention rules, you can check them out here. If those don’t meet your needs you can extend them using a commitlint configuration file. You can then add the commitlint as a hook using Husky (directions here). After you set that up every time you try to run git commit it will first pass your commit message through the linter and either it will succeed or get rejected with a violation reason if it doesn’t comply with the rules.

If you find any other tools that you would like to share please open a PR.