Making great commit messages with Commitizen¶
Commitizen, cz
, is a tool used by the CHIME FRB Group to create standardised messages when committing changes to git. In addition to this, it can also bump the version of the repo automatically based on the commit history and will keep track of changes in a CHANGELOG
.
Installing Commitizen
Commitizen can be installed by simply entering the following command:
Committing with Commitizen¶
Before we can commit using Commitizen, we need to make some changes in the repository. Add the python file below to your repository:
Now, to commit changes using Commitizen, run this command in your terminal:
Commitizen will display a series of prompts for you to answer, from which it will formulate your commit message.
Result
So let's answer these prompts for the changes that we made to plot_sin.py
, pressing enter after each one.
- The type of change that we made is "feat: A new feature", so use the arrow keys to move down and select it.
- For the next question, we only edited one file so enter its name,
plot_sin.py
. - Next, describe the changes that you made to this file, I'll let you decide what to answer for that one.
- The following prompt is a place to add extra information if you were unable to fit everything that you wanted to say above.
- Did these changes break anything? No.
- Lastly, we don't need to write any footer info, so press enter one last time.
Congratulations!! You've just made your first commit with Commitizen :)
Bump¶
Commitizen can also keep track of versioning for your repository. Versioning is important as it allows users to know when breaking changes have been made to the code. This way they know that they'll need to have more time to iron-out any issues arising from the new changes. To automatically bump up the version based on the commits that have been made, run:
The version format follows semantic versioning = MAJOR.MINOR.PATCH
.
Increment | Description | Conventional commit map |
---|---|---|
MAJOR |
Breaking changes introduced | BREAKING CHANGE |
MINOR |
New features added | feat |
PATCH |
Fixes | fix + everything else |
A changelog can be generated along with the new version when bumping by appending the flag --changelog
or -ch
.
However, bump requires a config file, and so we will return to practice this at a later stage.
Changelog¶
A changelog can be automatically generated using all commit messages that follow the Commitizen format. This is why it is important to write well-formatted commit messages! A changelog does what it says on the tin, it keeps a log of all changes that have been made between versions. To create a changelog with Commitizen, simply use this command:
The format of the changelog is:
Wherechange_type
, scope
, and message
are taken from the git commit
message and version
and
date
are taken from the tags.
Go ahead and run the command to generate a changelog in your repository. If you look inside the new
CHANGELOG.md
file you should see something like this:
Next step¶
If you are now able to confidently write commit messages with Commitizen, then you are ready to move on to learn about Pre-Commit.