gitHooks: commit-msg

简介: gitHooks: commit-msg

一、背景

提交代码时,如果不能形成有效约束,依靠个人的自觉,这样即使每个人是积极的状态,但是每个人的知识构成不同,也会造成提交风格迥异。

引入今天的主角,gitHooks配置commit-msg

二、实现步骤

2.1、配置package.json,增加commit-msg

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

2.2、根目录创建scripts文件夹

2.3、scripts文件夹创建文件verifyCommitMsg.js

2.4、verifyCommitMsg.js文件内容

const chalk = require('chalk')  // eslint-disable-line
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|build)(\(.+\))?: .{1,50})/
if (!commitRE.test(msg)) {
  console.log()
  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(v-model): handle events on blur (close #28)`)}\n\n` +
    chalk.red(`  See .github/COMMIT_CONVENTION.md for more details.\n`) +
    chalk.red(`  You can also use ${chalk.cyan(`npm run commit`)} to interactively generate a commit message.\n`)
  )
  process.exit(1)
}

2.5、这个时候提交代码就会起到作用了。

配置前提交代码可以任意提交,配置后要按照规则提交。

这样是ok的:

这样是有问题的:

出现拦截:

三、简要说明

commit代码时要根据本次内容不同加上响应的前缀,前缀list:

feat|fix|docs|style|refactor|perf|test|workflow|ci|chore|types|build

分别对应了:

feat:新功能

fix:修改bug

docs:文档修改

style:代码格式修改,注意不是css修改(例如分号修改)

refactor:代码重构(重构,在不影响代码内部行为、功能下的代码修改)

perf:更改代码,以提高性能

test:测试用例新增、修改

workflow:工作流相关文件修改

ci:持续集成想相关文件修改

chore:其他修改(不在上述类型的修改)

types:类型、特征

build:影响项目构建或依赖项修改

四、欢迎交流指正。

相关文章
|
开发工具 git 开发者
写出好的 commit message
为何要关注提交信息 加快Reviewing Code的过程 帮助我们写好release note 5年后帮你快速想起来某个分支,tag或者 commit增加了什么功能,改变了哪些代码 让其他的开发者在运行 git blame 的时候想跪谢 总之一个好的提交信息,会帮助你提高项目的整体质量 基本要求 第一行应该少于50个字。
967 0
|
测试技术 开发工具 git
Commit Message 规范
Commit Message 规范
|
Shell 开发工具 git
(极简解决)git commit 时出现:please enter the commit message for your changes
(极简解决)git commit 时出现:please enter the commit message for your changes
1158 0
|
Oracle 关系型数据库
【转】Alert Log Messages: Private Strand Flush Not Complete [ID 372557.1]
文章转自:oracle 官网 Modified 01-SEP-2010     Type PROBLEM     Status MODERATED   In this Document  Symptoms  Cause  Solution  References Plat...
863 0
|
开发工具 git
git commit 弹出编辑器后报错: Aborting commit due to empty commit message.
使用终端提交代码 "git commit" 能正常弹出 设置的编辑器,但是直接被空消息提交上来导致无效。 git commit 使用了插件 # git-extras 简化命令 gc == git commit 解决方法: $ git config --global core.editor "subl -w -f" "subl -f" 表示设置默认启动的编辑器,-w表示等待编辑器提交之后, -f 为一个参数 让它不要 fork。
5871 0
|
9月前
|
开发工具 git
Git Commit Msg
Git Commit Msg
83 0
|
缓存 Oracle 关系型数据库
Oracle中控制commit的三个参数 commit_write, commit_logging和 commit_wait
Oracle中控制commit的动作有三个参数 commit_write, commit_logging和 commit_wait,按重要性分别说明如下
336 0
|
分布式计算 Hadoop 关系型数据库

热门文章

最新文章