前端代码提交规范(git cz)

背景
最近在提交代码的时候发现每次提交的代码说明都是层次不齐的,看上去让人感觉到特别的凌乱。第一:让人看上去感觉这个程序猿好像不是“正规”出身,再一让自己在回溯代码的时候没有任何头绪。

简介
所以就找到了一款适合大众而且也是相当知名的代码提交规范:commitizen(git cz),这款工具也是最早 Angular 团队提交代码的时候用的一套规范,在现今 github 和团队场景中运用十分广泛的工具。

说明
commitizen 也可以简写为:git cz 格式化工具,为我们提供规范了代码的提交信息,在团队中使用能统一提交信息,在往后的代码回溯或者日志生成能够快速的查找到对应的目录。

安装
npm 安装 commitizen

npm install commitizen

yarn 安装 commitizen

yarn add commitizen

配置命令
等待安装完之后在对应的项目下的 package.json 文件夹下 添加如下命令:

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

前端代码提交规范(git cz)_第1张图片

添加完 在控制面板中输入 git cz 命令就会出现对应的 commitizen 提交规范步骤 如下图:

git cz
? 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, formatting, 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 

刚开始看不懂,没关系,下面有翻译的版本。但是我并不推荐你安装汉化版的,要尝试看英文文档 养成良好的习惯

feat: A new feature
壮举:新功能

fix: A bug fix
修复:错误修复

docs: Documentation only changes
docs:仅文档更改

style: Changes that do not affect the meaning of the
样式:不影响代码含义的更改(空格、格式、缺少分号等


refactor: A code change that neither fixes a bug nor
重构:既不修复错误也不添加功能的代码更改


perf: A code change that improves performance
perf:提高性能的代码更改


test: Adding missing tests or correcting existing tests
测试:添加缺失的测试或纠正现有的测试

build: Changes that affect the build system or external dependencies
build:影响构建系统或外部依赖项的更改

ci: Changes to our CI configuration files and scripts
ci:对我们的 CI 配置文件和脚本的更改

chore: Other changes that dont modify src or test
杂项:不修改 src 或测试文件的其他更改

revert: Reverts a previous commit
还原:还原以前的提交

以上基本上就是对照的中文说明。前期可以多尝试看看,后期再提交的时候自然而然就熟悉提交的说明了。

如果你修改了bug,那么第一步就是选择 fix选项:fix

第二步会出现一个 Specify a scope:意思就是这次修改的文件夹是那部分,我一般选择 src/home/banner…等等,这些文件夹可以选择更改的目录

第三步会出现write a short description:意思是写一段简短的描述。我一般会:修改了…bug等

其余选项可以直接敲回车就可,最后生成的commitizen 信息就是:fix(src/home/banner): 修改了…bug。是不是看上去很清晰!

好了,今天这一篇就是介绍 前端工程化的一些 规范工具,有什么问题欢迎随时留言~

你可能感兴趣的:(前端,git)