Skip to content

Instantly share code, notes, and snippets.

@xihajun
Forked from ebwood/conventional_commit_library.md
Last active December 6, 2022 16:42
Show Gist options
  • Save xihajun/405bdb68876606a05efadf82093eaf91 to your computer and use it in GitHub Desktop.
Save xihajun/405bdb68876606a05efadf82093eaf91 to your computer and use it in GitHub Desktop.
commitlint + husky + commitizen

commitlint + husky + commitizen

  1. git init(if project is not git repository).

  2. install node:

    brew install node
  3. add node_modules and other conventional commit files and folders to .gitignore:

    echo "
    ## conventional commit related files
    node_modules/ 
    .husky/
    commitlint.config.js
    package-lock.json
    package.json
    ">> .gitignore
  4. install commitlint:

    npm install @commitlint/{cli,config-conventional} --save-dev
  5. export commitlint/config-conventional:

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

Husky v7 won't use the hooks configuration from package.json or .huskyrc.json file.
So you should use files like pre-commit, commit-msg, prepare-commit-msg to use the hooks.
see the answer in stackoverflow.

  1. install husky:

    npm install husky --save-dev
  2. enable git hooks:

    npx husky install
  3. make git commit can use git cz hook:

    npx husky add .husky/prepare-commit-msg "exec < /dev/tty && git cz --hook || true"
    
  4. add commitlint in husky with commit-msg:

    npx husky add .husky/commit-msg "npx --no-install commitlint --edit"
    echo "$(cat .husky/commit-msg) \"\$1\"" >> .husky/commit-msg
  5. install commitizen:

    npm install commitizen --save-dev
  6. initialize your project to use the cz-conventional-changelog adapter by typing:

    commitizen init cz-conventional-changelog --save-dev --save-exact
  7. finally, use git commit or cz or cz commit or git cz or git-dz to commit with convention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment