Introduction to Commitizen
Commitizen is a tool designed to standardize and streamline your project’s commit messages. This ensures that your versioning is easier to manage and your commit history is cleaner and more understandable. By enforcing a particular convention, Commitizen helps teams to maintain a uniform style, which can help with automation processes and improve collaboration. Below, we’ll explore various APIs provided by Commitizen along with examples to help you get started quickly.
Installing Commitizen
Before using Commitizen, you need to install it. The following code snippet shows how to install Commitizen using npm:
npm install -g commitizen
Initialize a Project with Commitizen
To initialize a project to use Commitizen, run:
commitizen init cz-conventional-changelog --save-dev --save-exact
Create a Commit using Commitizen
Once initialized, you can create a standardized commit message using:
git cz
This will prompt you with several questions about the commit you are making and generate a properly formatted commit message.
Using Custom Adapters
Commitizen supports the use of custom adapters. Here’s how you can configure a custom adapter:
commitizen init your-adapter --save-dev --save-exact
API Examples
-
How to Check if a Project is Commitizen-friendly
commitizen check
Committing with Conventional Changelog
commitizen init cz-conventional-changelog
Manual Commit Format Enforcement
echo "message" | commitizen -m
Displaying Commitizen Version
commitizen -v
Changing the Commit Message Root
commitizen --path
Example App with Commitizen
Let’s take a look at an example where Commitizen is integrated into a simple Node.js project.
{
"scripts": {
"commit": "git-cz"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
By adding the above configuration to your package.json
file, you make sure that every time you run npm run commit
, Commitizen will guide you through the commit process using the conventional changelog format.
By incorporating Commitizen into your workflow, you standardize and clarify your commit history, making it easier to manage and understand over time.
Hash: c517b6e15373b5e9a315fabbee092a7723b6c1467959b2a1b4602e7211485f46