Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

git-conventional-commits

qoomon20.6k2.8.0

git conventional commits util

readme

Git Conventional Commits starline

npm

[!TIP] Also have a look at Git Conventional Commits Cheat Sheet

Changelog

see CHANGELOG.md

Usage

npx git-conventional-commits <command>

Commands

ℹ add help parameter -h to commands to list all possible options

  init [options]                               create a config file template `git-conventional-commits.yaml`
  version [options]                            determine version from conventional commits
  changelog [options]                          generate change log from conventional commits
  commit-msg-hook [options] <commit-msg-file>  check for conventional commit message format

First Usage

  • Run npx git-conventional-commits init
  • Adjust config file git-conventional-commits.yaml to your needs

Config File

Example git-conventional-commits.yaml

---
convention:
  commitTypes:
  - feat     # Commits, that add or remove a new feature to the API or UI
  - fix      # Commits, that fix a API or UI bug of a preceded feat commit
  - refactor # Commits, that rewrite/restructure your code, however do not change any API or UI behaviour
  - perf     # Commits are special `refactor` commits, that improve performance
  - style    # Commits, that do not affect the meaning (white-space, formatting, missing semi-colons, etc)
  - test     # Commits, that add missing tests or correcting existing tests
  - build    # Commits, that affect build components like build tool, ci pipeline, dependencies, project version, ...
  - ops      # Commits, that affect operational components like infrastructure, deployment, backup, recovery, ...
  - docs     # Commits, that affect documentation only 
  - chore    # Miscellaneous commits e.g. modifying `.gitignore`
  - docs
  - merge
  commitScopes: []
  releaseTagGlobPattern: v[0-9]*.[0-9]*.[0-9]*
changelog:
  commitTypes:
  - feat
  - fix
  - perf
  - merge
  includeInvalidCommits: true
  commitScopes: []
  commitIgnoreRegexPattern: "^WIP "
  headlines:
    feat: Features
    fix: Bug Fixes
    perf: Performance Improvements
    merge: Merges
    breakingChange: BREAKING CHANGES
  commitUrl: https://github.com/qoomon/git-conventional-commits/commit/%commit%
  commitRangeUrl: https://github.com/qoomon/git-conventional-commits/compare/%from%...%to%?diff=split
  issueRegexPattern: "#[0-9]+"
  issueUrl: https://github.com/qoomon/git-conventional-commits/issues/%issue%
  • convention

    • commitTypes an array of expected commit types
      • show warnings for unexpected types
      • if not set or empty commit type validation is disabled
      • e.g. ["feat", "fix", "doc", "style"]
    • commitScopes an array of expected commit types
      • show warnings for unexpected scopes
      • if not set or empty commit scope validation is disabled
      • e.g. ["ui", "database"]
    • releaseTagGlobPattern glob pattern to filter for release tags
      • release tags must contain semantic version ([0-9]+\.[0-9]+\.[0-9]+)
      • default *
    • issueRegexPattern regex pattern to find issue IDs
      • e.g. Jira issue pattern [A-Z]{3,}-\\d+
  • changelog

    • commitTypes filter commits by type
      • a subset of convention.commitTypes plus
        • merge commits
      • if not set or empty commit type filter is disabled
      • e.g. ["feat", "fix", "merge"]
    • commitScopes filter commits by scopes
      • a subset of convention.commitScopes
      • if not set or empty commit scope filter is disabled
      • e.g. ["ui"]
    • includeInvalidCommits include commits without valid type: default: true
      • if set to false all commits with undefined commitTypes will be removed from changelog
    • commitIgnoreRegexPattern filter commits by commit subject regex
      • default ^WIP
    • headlines a map of headline identifier and actual headline
      • a subset of changelog.commitTypes plus
        • breakingChange Breaking Changes Section
      • e.g. { "feat": "Features", "fix": "Bug Fixes", "breakingChange": "BREAKING CHANGES"}
      • default { "feat": "Features", "fix": "Bug Fixes", "merge": "Merges", "breakingChange": "BREAKING CHANGES"}
    • commitUrl an URL template for generating markdown links to repository commits
      • %commit% commit hash placeholder
      • eg https://github.com/qoomon/git-conventional-commits/commit/%commit%
      • if not set or empty link generation is disabled
    • issueUrl an URL template for generating markdown links to an issue tracker
      • %issue% issue id placeholder
      • eg https://jira.example.org/browse/%issue%
      • if not set or empty link generation is disabled

Automatically Validate Commit Message Convention before Commit

To automatically validate commit messages, a git hook can be used in the commit-msg stage. The hook can be created either manually or using the pre-commit framework.

Setup with the pre-commit framework

  • Create .pre-commit-config.yaml file in the root directory of your repository with following content.
      repos:
      - repo: https://github.com/qoomon/git-conventional-commits
        rev: <RELEASE_TAG>
        hooks:
          - id: conventional-commits
  • Install the pre-commit framework pip install pre-commit
  • Install the commit-msg hook pre-commit install -t commit-msg

Setup manually

  • Setup Commit Message Hook to

    • Navigate to your repository directory cd <repository-path>
    • Create git hook directory mkdir .git-hooks
    • Set update hooksPath git config core.hooksPath .git-hooks
    • Create commit message hook script and make it executable

      • touch .git-hooks/commit-msg && chmod +x .git-hooks/commit-msg
      • Open .git-hooks/commit-msg with your favorite editor and paste following script

        #!/bin/sh
        
        # fix for windows systems
        PATH="/c/Program Files/nodejs:$HOME/AppData/Roaming/npm/:$PATH"
        
        npx git-conventional-commits commit-msg-hook "$1"
    • Add and commit .git-hooks/commit-msg to repository

      [!IMPORTANT] Whenever you clone your repository with git hooks you need to enable git hooks once again
      git config core.hooksPath .git-hooks

Release Workflow with git-conventional-commits

  • Determine version by npx git-conventional-commits version
  • Update version in project files
    • Commit version bump git commit -am'build(release): bump project version to <version>'
  • Generate change log by npx git-conventional-commits changelog --release <version> --file 'CHANGELOG.md'
    • Commit change log git commit -am'docs(release): create <version> change log entry'
  • Tag commit with version git tag -a -m'build(release): <version>' '<version-prefix><version>'
  • Push all changes git push
  • Build and upload artifacts

Integration with existing repository

If you have an large existing repo with no release tags e.g. v1.0.0, or if you want the first changelog to be tidy, you need to create a release tag first.

  • Create release tag for specific commitgit tag -a -m'build(release): 0.0.0' 'v0.0.0'
  • Push tag git push origin v0.0.0 This way npx git-conventional-commits will only considre commits based on the commit the release tag is pointing at.

Projects Using git-conventional-commits


Build/Release

  • npm install
  • npm test
  • npm login
  • npm publish

changelog

2.6.32023-03-02 (ad1d56c...a64d54f)

Bug Fixes

  • use full commit hashes for links (a64d54f)

2.6.02023-02-28 (aafcc05...aafcc05)

Features

changelog
  • adjust changelog styling (aafcc05)

2.5.22023-02-28 (15ea67b...15ea67b)

Bug Fixes

  • fix missing new line for commit line (15ea67b)

2.5.02023-01-27 (5d6f92f...5d6f92f)

Features

  • init command add commit message hook (5d6f92f)

2.4.12023-01-17 (ea1c647...ea1c647)

Bug Fixes

  • add missing default.yaml (ea1c647)

2.4.02022-12-15 (e19dbd5...e19dbd5)

Features

  • add yaml config support (e19dbd5)

2.3.12022-12-14 (5d29d9b...a75269d)

Bug Fixes

  • fix git command sytax for windows (a75269d)

2.3.02022-11-06 (d7e4124...15a031e)

Features

  • change default merge headline to just 'Merges' (d7e4124)
  • create inline Markdown links for issue references (15a031e)

2.2.02022-11-06 (9e026c5...d0b5b6b)

Features

  • add support for bitbucket merge messages (d0b5b6b)

2.1.22022-09-20 (9e026c5...68a02b6)

Bug Fixes


2.1.12022-08-17 (b8d8a18...940f809)

Bug Fixes

  • handle empty repository and no release tag (940f809)

2.1.02022-07-30 (0e01b77...2ef8c09)

Features

  • add support for the pre-commit framework (#102) (0e01b77)

2.0.02022-07-19 (752f806...ed7cb3b)

Features

  • ignore pre-release version tags e.g. v1.2.3-SNAPSHOT or v1.2.3-rc1 (df7be15)
  • do not recalculate version, if version tag points on commit anchor (8cd6c74)
changelog
  • release date will be taken from commit date (ed7cb3b)

1.4.22022-07-15 (6d20004...19d2d70)

Bug Fixes

  • I messed up a little, so this is a working version again (19d2d70)

1.4.02022-07-15 (8c71120...31b9fa7)

Features

  • support breaking change syntax in commit subject (651a6b3)

1.3.02022-07-14 (e7e8c4f...06d3556)

Bug Fixes

  • always include breaking changes in changelog (#96) (d43723d)

1.2.32022-07-11 (e2aa89a...b45ae70)

Bug Fixes

  • Handle development version increments according to SemVer specification (#93) (8226d92)

1.2.02022-02-25 (3b1fbbf...a5e7851)

Features

  • add includeInvalidCommits option (#74) (a5e7851)

1.1.02021-08-31 (1746e1c...483aa5f)

Features

  • add --commit option to generate version and changelog for specific commit e.g. v1.0.0 (483aa5f)