Que sera, sera



标签: 学习,文章,Git


git add .
git commit -m '添加代码注释'




   ERROR  invalid commit message format.

  Proper commit message format is required for automated changelog generation. Examples:

    feat(compiler): add 'comments' option
    fix(v-model): handle events on blur (close #28)

  See .github/COMMIT_CONVENTION.md for more details.
  You can also use npm run commit to interactively generate a commit message.

commit-msg hook failed (add --no-verify to bypass)


怎么提交还会报错?这看上去不像冲突啥的啊。npm run commit 又是啥? 键入npm run commit

cz-cli@2.10.1, cz-conventional-changelog@2.1.0

Line 1 will be cropped at 100 characters. All other lines will be wrapped after 100 characters.

? Select the type of change that you're committing: (Use arrow keys)
❯ feat:     A new feature 
  fix:      A bug fix 
  docs:     Documentation only changes 
  style:    Changes that do not affect the meaning of the code (white-space, format
ting, missing semi-colons, etc) 
  refactor: A code change that neither fixes a bug nor adds a feature 
  perf:     A code change that improves performance 
  test:     Adding missing tests or correcting existing tests 
(Move up and down to reveal more choices)



  build:    Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm) 
  ci:       Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs) 
  chore:    Other changes that don't modify src or test files 
  revert:   Reverts a previous commit 


选择对应的类型可以清楚明了的说明本次提交的目的。 接下来还会问一些问题:

? What is the scope of this change (e.g. component or file name)? (press enter to s
? Write a short, imperative tense description of the change:
? Provide a longer description of the change: (press enter to skip)
? Are there any breaking changes? No
? Does this change affect any open issues? No


按着这个一步一步来,一个规范的的commit就出来了。 嗨呀,真的好啊,还能强制性的规范commit,所有项目上都弄这么个东西,这么一来所有项目的commit都会变得清晰明了。 这个命令到底执行了啥呢?跑去package.json文件中去看,有这么一句"commit": "git-cz"git-cz又是啥呢?接着又去google。 google git-cz 第一条点进去,是一个插件,叫commitizen。 切到自己的项目,npm安装,package.jsonscripts添加指令,再在package.jsonconfig里添加:

  "config": {
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"



git add .
git commit -m 'x'

测试下。哈?怎么直接提交了?怎么没报错?这东西没用?npm run commit,这玩意儿有用呀,为啥直接提交不规范commit还能成功? 再看看vue的package.json怎么写的。

  "gitHooks": {
    "pre-commit": "lint-staged",
    "commit-msg": "node scripts/verify-commit-msg.js"
  "lint-staged": {
    "*.js": [
      "eslint --fix",
      "git add"



  • commit之前,执行lint-staged
  • 对commit的说明进行判定是否是符合规范的commit

lint-staged :对代码进行静态分析,试图找出潜在的问题。使用 lint-staged只会对每次提交文件进行检查。

  • 对所有提交的js文件进行eslint修复,修复后重新添加该文件到暂存区