Good Git Commit Message

同步链接: https://www.shanejix.com/posts/Good Git Commit Message/

why good commit

git commit 是当次 committing 更改的简短描述。良好的 commit message 不仅仅有利于与和他人合作,而且能很方便的追踪工作记录。

how to write

commit message 格式


    format: [emoji] <type>(scope): <message>

    - emoji:options

    - type: require

    - scope:require

    - message(description):  require

type

  • feat: a new feature
  • fix: a bug fix
  • improvement: an improvement to a current feature
  • docs: documention only chnage
  • style: everything related to styling
  • refactor: a code change that not neither a bug nor add a feat
  • test: everything related to testing
  • chore: updating build task,package manager config,etc

scope

当前 commit 影响范围

descript

当前 commit 简短描述

emojis type

one style

  • Good Git Commit Message when adding a file or implementing a feature
  • Good Git Commit Message when fixing a bug or issue
  • Good Git Commit Message when improving code or comments
  • Good Git Commit Message when improving performance
  • Good Git Commit Message when updating docs or readme
  • Good Git Commit Message when dealing with security
  • Good Git Commit Message when updating dependencies or data
  • Good Git Commit Message when a new release was built
  • Good Git Commit Message when refactoring or removing linter warnings
  • Good Git Commit Message when removing code or files

another style

  • Good Git Commit Message [tada] initial commit
  • Good Git Commit Message [Add] when implementing a new feature
  • Good Git Commit Message [Fix] when fixing a bug or issue
  • Good Git Commit Message [Refactor] when refactor/improving code
  • Good Git Commit Message [WIP]
  • Good Git Commit Message [Minor] Some small updates

gitHook

package.json

    "githook": {
      "pre-commit": "lint-staged",
      "commit-msg": "node scripts/verifyCommitMsg.js"
    }

scripts/verifyCommitMsg.js

const chalk = require("chalk");
// const msgPath = process.env.HUSKY_GIT_PARAMS;
const msgPath = process.env.GIT_PARAMS;
const msg = require("fs").readFileSync(msgPath, "utf-8").trim();

const commitRE =
  /^(v\d+\.\d+\.\d+(-(alpha|beta|rc.\d+))?)|((revert: )?(feat|fix|docs|style|refactor|perf|test|workflow|ci|chore|types)(\(.+\))?!?: .{1,50})/;

if (!commitRE.test(msg)) {
  console.error(
    `  ${chalk.bgRed.white(" ERROR ")} ${chalk.red(
      `invalid commit message format.`
    )}\n\n` +
      chalk.red(
        `  Proper commit message format is required for automated changelog generation. Examples:\n\n`
      ) +
      `    ${chalk.green(`feat(compiler): add 'comments' option`)}\n` +
      `    ${chalk.green(`fix(menu): handle events on blur (close #28)`)}\n\n` +
      chalk.red(`  See .gitlab/commit-convention.md for more details.\n`)
  );
  process.exit(1);
}

tools

commitizen

gitmoji-cli

references

作者:shanejix
出处:https://www.shanejix.com/posts/Good Git Commit Message/
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
声明:转载请注明出处!

上一篇:这是我见过最好的循环的写法


下一篇:2021_12_12自学笔记_Requests的基本使用和get请求