DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Developer Git Commit Hygiene
  • Eliminate Human-Based Actions With Automated Deployments: Improving Commit-to-Deploy Ratios Along the Way
  • Understanding Git
  • The Art of the Bug Fix: Boosting Software Quality Through Effective Git Commits

Trending

  • Transforming AI-Driven Data Analytics with DeepSeek: A New Era of Intelligent Insights
  • A Modern Stack for Building Scalable Systems
  • Apache Doris vs Elasticsearch: An In-Depth Comparative Analysis
  • Hybrid Cloud vs Multi-Cloud: Choosing the Right Strategy for AI Scalability and Security
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Using Conventional Commit in Projects

Using Conventional Commit in Projects

Check out this post to learn more about how to use conventional commit in your projects.

By 
Sathyabodh Mudhol user avatar
Sathyabodh Mudhol
·
Aug. 16, 19 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
10.4K Views

Join the DZone community and get the full member experience.

Join For Free

In this post, we will explore how to use conventional commit as well as the benefits of using it in your projects. Let's get started.

What Is It?

Conventional commit is a commit message standard first proposed by the Angular team to make their commit message uniform across different developers' check-ins. This standard gives a certain structure to commit and is helpful in building tools on top of commit messages. 

This standard is applicable to any version control and any programming language. But Git version control has many tools built and is easy to adapt for Git.

What Are the Benefits?

The conventional commit message spec gives us benefits like:

  1. All developers follow the same commit message format. This helps to capture all important information about the code changes being checked in.
  2. It helps with the Semver versioning of software. Thus, it will become easy to determine the next version of a product based on current commits present in the master starting from the last release tag. There are some node modules available as open-source that suggest the next version.
  3. It helps to auto-generate CHANGELOG.md to document release notes for each release. Since it is auto-generated, there would not be any mistake of missing any commits in release note or tiresome effort of writing CHANGELOG.
  4. It helps in automating releases if version control used is in GitHub/GitLab. There are tools like semantic release, standard version, conventional-github-releaser, and automating the release.

How to Use

Conventional commit message usage does not require any tool, but using tools helps in conforming to the message spec without really remembering it. It streamlines the process of creating commit messages, checking the message, and conforming to the standard.

I have used two node modules to create a commit message and checking the format. You need to install the node globally in your machine to make use of them. Install the node from https://nodejs.org/en/.

Commitizen

This is a very popular node tool used to create a commit message. It takes you through a set of questions about commit and prepares the commit message.

Local installation:

npm install --save-dev commitizen
npx commitizen init cz-conventional-changelog --save-dev --save-exact


cz-conventional-changelog is an adapter for commitizen to format the message. 

Once these tools are installed successfully, you can use command git-cz instead of git commit to invoke this tool. You can also have it as script inside package.json for ease of use.

Example commitizen usage:

(base) C02X66GTJGH5:quartz-acutator i322094$ git-cz
cz-cli@4.0.3, cz-conventional-changelog@3.0.2

? Select the type of change that you're committing: fix:      A bug fix
? What is the scope of this change (e.g. component or file name): (press enter to skip) 
? Write a short, imperative tense description of the change (max 67 chars):
 (32) add endpoint for managing quartz
? Provide a longer description of the change: (press enter to skip)
 Added new endpoint for managing quartz.\n - New end point for managing quartz jobs\n - Implemented as spring boot autoconfigure module
? Are there any breaking changes? No
? Does this change affect any open issues? (y/N) N


You can see that in the above output, to add a multi-line description, you need to use  \n as it does not identify a key as a continuation of the description. This is a little annoying but will do the job

Commit Message Validation

 Commitizen is a helper tool to format commit message. A developer may not install it or might use UI tools like SourceTree to do the commit. Commitizen does not provide any tool for UI like SourceTree. In such cases, we would want to check for the commit message before finalizing commit instead of discouraging the use of UI tools

We would need two things to achieve this:

Commitlint

This is another node module that will help in linting commit messages.

Local installation:

npm install --save-dev @commitlint/{cli,config-conventional}
echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js


Usage

echo 'fix: fix rollback issue' | npx commitlint

npx commitlint < commit_message.txt


Git Hook — commit-msg

Once you have commitlint, we need to have a way to invoking it before finishing commit. The commit-msg Git hook comes in handy here. This hook gets executed after the user has entered a commit message and before finishing a commit. If this hook exits with a status other than 0, then commit fails.

Below is the content of the commit-msg script. This has to be copied to the .git/hooks directory as .git folder contents are not copied when git clone is complete.

#! /bin/sh
export PATH=/usr/local/bin:$PATH
npx commitlint < $1
status=$?
if [ $status -gt 0 ]
then
        echo "Commit message does not follow conventional commit message spec"
        echo 'Please use "git-cz" instead of "git commit" command to format commit message according to conventional commit message spec'
fi
exit $status


We could put this script in any directory at the root of the repository so that this hook is maintained in our repository. For example, we need to create directory ' githooks' at the root of the repository and place git hooks there. Once the Git clone is done, the user can manually copy this to the .git/hooks directory.

This script will stop any commits which are not according to conventional commit format. This also gets executed when a commit happens from UI tools like SourceTree.

Note: To make this script work when committing from SourceTree, we need to add /usr/local/bin to the $PATH variable, or else it will complain that the 'npx' command cannot found.

Summary

In this post, we have seen the benefits of using conventional commit and how to set up tools to help with that. We can include all of the above steps in some script like 'setup.sh,' which does node module installation and the copying of Git hooks. This will help in reducing the steps required to do so after conducting Git cloning. This is a one-time operation after the cloning of repository. I have set up all these in one of my GitHub projects. Please refer to https://github.com/sathyabodh/quartz-acutator for the complete code.

Commit (data management)

Opinions expressed by DZone contributors are their own.

Related

  • Developer Git Commit Hygiene
  • Eliminate Human-Based Actions With Automated Deployments: Improving Commit-to-Deploy Ratios Along the Way
  • Understanding Git
  • The Art of the Bug Fix: Boosting Software Quality Through Effective Git Commits

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!