<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="https://angrynerds.co/blog/rss/xslt"?>
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Blog</title>
    <link>https://angrynerds.co/blog</link>
    <description />
    <generator>Articulate, blogging built on Umbraco</generator>
    <item>
      <guid isPermaLink="false">3509</guid>
      <link>https://angrynerds.co/blog/master-your-git-log-with-conventional-commits-in-6-steps/</link>
      <category>Development</category>
      <title>Master your git log with Conventional Commits in 6 steps</title>
      <description>&lt;p&gt;Such messages tell us absolutely nothing about the project, and soon turn following changes into hell. Sad reality of being a software developer? &lt;/p&gt;
&lt;div style="display: block; width: 500px; margin: 0 auto;"&gt;
&lt;img src="https://angrynerds.co/media/2034/gitcommit.png"&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br&gt;&lt;/p&gt;
&lt;div align="center"&gt;

&lt;i&gt;Source: &lt;a href="https://xkcd.com/1296/" target="_blank"&gt;xkcd&lt;/a&gt;&lt;/i&gt;

&lt;/div&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Not anymore! We hope that after reading this article you will no longer have problems with self-discipline, and you will learn how to better document your work. We will also show you how to automate it all, avoid inappropriate commit message format and properly version the modules. &lt;/p&gt;
&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Semantic Versioning, Conventional Commits and related tools are powerful – and very easy to use! They’ll not only take your skills to the next level, but also speed up the development process. Their advantages are significant: &lt;/p&gt;
&lt;p&gt;→ generating changelogs and determining the next module version can be automated (based on commit messages), &lt;br&gt;
→ the whole process of building and publishing the module can be automated, &lt;br&gt;
→ contributing to your project is easier thanks to a more structured commit history.&lt;/p&gt;
&lt;p&gt;Before we start with Conventional Commits, we need to know what the Semantic Versioning is.&lt;/p&gt;
&lt;h2&gt;1. Semantic Versioning&lt;/h2&gt;
&lt;p&gt;You probably already use something similar to Semantic Versioning in your projects, but that's not enough, especially when the project is a complex one. At some point you might get stuck in a dependency hell – and you really wouldn’t like that:  
&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;quot;In the world of software management there exists a dreaded place
called &amp;quot;dependency hell&amp;quot;. The bigger your system grows and the more
packages you integrate into your software, the more likely you are to
find yourself, one day, in this pit of despair. In systems with many
dependencies, releasing new package versions can quickly become a
nightmare. If the dependency specifications are too tight, you are in
danger of version lock (the inability to upgrade a package without
having to release new versions of every dependent package). If
dependencies are specified too loosely, you will inevitably be bitten
by version promiscuity (assuming compatibility with more future
versions than is reasonable). &lt;strong&gt;Dependency hell is where you are when
version lock and/or version promiscuity prevent you from easily and
safely moving your project forward.&lt;/strong&gt;&amp;quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;i&gt;Source: &lt;a href="https://semver.org/" target="_blank"&gt;semver.org&lt;/a&gt;&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;So, what is Semantic Versioning?&lt;/p&gt;
&lt;div align="center"&gt;
&lt;img src="https://angrynerds.co/media/2035/semver.png"&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br&gt;
It's the way we version the project, and the main guidelines are the following:&lt;br&gt;
1.	Increment major version when you make incompatible API changes&lt;br&gt;
2.	Increment minor version when you add functionality in a backwards compatible manner&lt;br&gt;
3.	Increment patch version when you make backwards compatible bug fixes&lt;br&gt;
4.	Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format&lt;/p&gt;
&lt;p&gt;And that's it! Isn't it simple? You can learn more about Semantic Versioning at &lt;a href="https://semver.org/" target="_blank"&gt;semver.org&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;2. Conventional Commits&lt;/h2&gt;
&lt;p&gt;The big questions is: which version should we increment? Conventional Commits come to the rescue! This lightweight specification provides an easy set of rules for creating an explicit commit history. Features, fixes and breaking changes made in commit messages allow to determine which version should be released next.&lt;/p&gt;
&lt;div style="display: block; width: 550px; margin: 0 auto;"&gt;
&lt;img src="https://angrynerds.co/media/2033/add-commit.png"&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;The commit message should be structured as follows:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;type(optional scope): description
[blank line]
[optional body]
[blank line]
[optional footer(s)]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;br&gt;
Types of commits:&lt;br&gt;
• fix: it patches a bug in your codebase (this correlates with PATCH in semantic versioning).&lt;br&gt;
• feat: it introduces a new feature to the codebase (this correlates with MINOR in semantic versioning).&lt;br&gt;
• BREAKING CHANGE: a commit that has a footer BREAKING CHANGE:, or appends a ! after the type/scope, introduces a breaking API change (correlating with MAJOR in semantic versioning). A BREAKING CHANGE can be part of commits of any type.&lt;br&gt;&lt;/p&gt;
&lt;p&gt;Types other than fix and feat are of course allowed - the Angular convention recommends: build, chore, ci, docs, style, refactor, perf, test, and others. Learn more here: &lt;a href="https://www.conventionalcommits.org/en/v1.0.0/" target="_blank"&gt;conventionalcommits.org&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;3. Lint commit messages&lt;/h2&gt;
&lt;p&gt;Once you know what Conventional Commits are, it's a good idea to be consistent and follow these rules, and preferably use a lint to keep a wrong commit message from passing on to the git history. With this tool, you will find out where you made a mistake when writing your message, and get tips on how to fix it.&lt;/p&gt;
&lt;p&gt;How to use it?&lt;/p&gt;
&lt;p&gt;Install commitlint dependencies:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm install --save-dev @commitlint/config-conventional @commitlint/cli
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;br&gt;
Create commitlint.config.js file with the following content:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;module.exports = {extends: ['@commitlint/config-conventional']};
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;br&gt;
Install husky:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm install --save-dev husky
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;br&gt;
Extend your package.json:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// package.json 
{
  &amp;quot;husky&amp;quot;:
    {
      &amp;quot;hooks&amp;quot;:
        {
          &amp;quot;commit-msg&amp;quot;: &amp;quot;commitlint -E HUSKY_GIT_PARAMS&amp;quot;
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;br&gt;
Test your latest commit:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npx commitlint --from HEAD~1 --to HEAD –verbose
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;br&gt;
This configuration is enough for a start, and if you want to learn more about the potential of this tool, have a look here: &lt;a href="https://commitlint.js.org/#/guides-local-setup" target="_blank"&gt;commitlint.js.org&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;4. Conventional Changelog&lt;/h2&gt;
&lt;p&gt;How to generate a changelog with Conventional Commits? There are several ways to do this, but the best one is &lt;code&gt;conventional-changelog-cli&lt;/code&gt;, which is a standardized cli tool.
How to use this tool?
Just install it globally using &lt;code&gt;npm install -g conventional-changelog-cli&lt;/code&gt;
If this is your first time using this tool, and you want to generate all previous changelogs, you could do it as follows: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;conventional-changelog -p angular -i CHANGELOG.md -s -r 0
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;br&gt;
You could use &lt;code&gt;conventional-changelog -p angular -i CHANGELOG.md -s&lt;/code&gt; to extend the changelog with the changes since the last version.
All available command line parameters can be listed using CLI: &lt;code&gt;conventional-changelog –help&lt;/code&gt;.
Get packages at &lt;a href="https://github.com/conventional-changelog/conventional-changelog" target="_blank"&gt;conventional-changelog&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;5. npm version&lt;/h2&gt;
&lt;p&gt;Okay, we know how to generate a changelog, but how to automate it?
To do this, we will use the &lt;code&gt;npm version&lt;/code&gt; script and it's pretty easy to do, just take a look at this command:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm version [ | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid= ] | from-git]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;br&gt;
For example, you can use such combinations:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;npm version major
npm version minor
npm version patch
npm version prerelease --preid=alpha
npm version prerelease --preid=beta
npm version prerelease --preid=rc
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;br&gt;
Once you know what the npm version command looks like, you can upgrade it with an additional changelog feature.
Just type into package.json scripts:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;quot;version&amp;quot;: &amp;quot;conventional-changelog -p angular -i CHANGELOG.md -s &amp;amp;&amp;amp; git add CHANGELOG.md&amp;quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;br&gt;
This will extend &lt;code&gt;CHANGELOG.md&lt;/code&gt; file with a log of recent changes in the code, based on the commit messages.
You could also use preversion and postversion scripts to run tests before the version script, and push changes or publish package after that. Learn more here: &lt;a href="https://docs.npmjs.com/cli/version" target="_blank"&gt;docs.npmjs.com/cli/version&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;6. .npmrc&lt;/h2&gt;
&lt;p&gt;Can the process of versioning be even more automated? Sure!
By adding a &lt;code&gt;.npmrc&lt;/code&gt; file you could also automate your commit message and set your tag prefix.
To do this, simply create &lt;code&gt;.npmrc&lt;/code&gt; file or run the &lt;code&gt;npm config&lt;/code&gt; command with the following content:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;tag-version-prefix=&amp;quot;&amp;quot;
message=&amp;quot;chore(release): %s :tada:&amp;quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;br&gt;
This way, every time a new version is called up, a new commit will be created with a Conventional Commit message. Learn more about the configuration here: &lt;a href="https://docs.npmjs.com/configuring-npm/npmrc.html" target="_blank"&gt;docs.npmjs.com/configuring-npm/npmrc&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;As you can see, a few easy steps can take your project management to a higher level, and help you stop treating commit messages like a burden. &lt;/p&gt;
&lt;p&gt;This article is also a good introduction to process automation in software development. What we have shown is only one of the possibilities! You have many conventions to choose from, you can expand your scripts with additional features and adapt them to each of your projects. &lt;/p&gt;
&lt;h3&gt;Don’t be afraid to commit – and enjoy the coding!&lt;/h3&gt;
&lt;p&gt;&lt;br /&gt; &lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;strong&gt;About the Author&lt;/strong&gt;&lt;br /&gt; 
&lt;a href="https://www.linkedin.com/in/aleksander-niedzwiedz/" target="_blank"&gt;Aleksander Niedźwiedź&lt;/a&gt; is an ambitious young lad who, despite only a few years of professional experience, has already proven to be a talented developer. At Angry Nerds, he specializes in front-end development, but he has also some skills in back-end technologies. He’s also up to date with the latest trends and best practices in software development. Aleksander likes to spend his free time in an active way, so you can spot him practicing various sports. &lt;/p&gt;
</description>
      <pubDate>Tue, 28 Apr 2020 10:27:32 Z</pubDate>
      <a10:updated>2020-04-28T10:27:32Z</a10:updated>
    </item>
  </channel>
</rss>