Skip to content

Instantly share code, notes, and snippets.

@virtuallyunknown
Created December 7, 2024 17:45
Show Gist options
  • Save virtuallyunknown/e91b0309aa9edf85ac6749c4012a8031 to your computer and use it in GitHub Desktop.
Save virtuallyunknown/e91b0309aa9edf85ac6749c4012a8031 to your computer and use it in GitHub Desktop.
Git commit message formatting guide

Git commit message formatting guide

Commit types

  • build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
  • chore: Other changes that don't modify src or test files
  • ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
  • docs: Documentation only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that neither fixes a bug nor adds a feature
  • revert: Reverts a previous commit
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • test: Adding missing tests or correcting existing tests

Scopes

Example:

chore(package): upgraded x dependency

Breaking changes

Example

fix!: upgraded x dependency
fix(package)!: upgraded x dependency

Linking a pull request to an issue using a keyword

Use one of the keywords, along with the issue number.

  • close
  • closes
  • closed
  • fix
  • fixes
  • fixed
  • resolve
  • resolves
  • resolved

Example

chore: closes #12

Install commitlint

pn add --global @commitlint/cli @commitlint/config-conventional

Create the global hook file

mkdir -p ~/.config/git/hooks
touch ~/.config/git/hooks/commit-msg
#!/bin/sh

echo 'Running commitlint on commit message...'
commitlint --extends "$(pnpm root -g)/@commitlint/config-conventional/lib/index.js" --edit ${1}

Configure git to use the global hook

  • Set a global git config path
git config --global core.hooksPath ~/.config/git/hooks

This will only take effect on newly created repositories. The hook needs to be manually added to existing repos.


Emojis for commit types:

  • build: πŸ“¦
  • chore: 🏑
  • ci: πŸ€–
  • docs: πŸ“–
  • examples: πŸ€
  • feat: πŸš€
  • fix: 🩹
  • perf: πŸ”₯
  • refactor: πŸ’…
  • revert: βͺ
  • style: 🎨
  • types: 🌊
  • test: βœ…

Sources

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