美文网首页
Git(Commitizen + husky + Git hoo

Git(Commitizen + husky + Git hoo

作者: 帝王弦 | 来源:发表于2023-12-10 17:08 被阅读0次

    1. 官网链接

    vite 官网

    pnpm官网

    Git 图形化

    2. git 常用命令

    //初始化项目仓库
    git init
    
    //管理 Git 仓库中的远程仓库
    //新增远程仓库
    git remote add origin 仓库地址(建议直接使用 ssh)
    //修改指定远程仓库的 URL
    git remote set-url <remote_name> <new_url>
    //删除
    git remote remove <remote_name>
    //远程仓库重命名
    git remote rename <old_name> <new_name>
    
    //分支
    //切换分支
    git checkout <branch-name>
    //创建并切换分支
    git checkout -b <branch-name>
    //删除分支
    git branch -d <branch-name>
    //查看所有分支
    git branch -a
    
    //提交
    git push origin dev ( -uf 强制推送)
    
    //合并
    git merge --on-ff "描述" <其他分支名>
    

    3. 全局安装commitizen

    commitizen规范的格式提交Git commit

    pnpm install -g commitizen
    

    配置commit message

    pnpm install -g cz-conventional-changelog
    
    echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc
    
    1. 自定义提交规范
    pnpm i cz-customizable -D
    

    以下配置添加到 package.json中

    "config": {
    
       "commitizen": {
    
         "path":"node_modules/cz-customizable"
    
       }
    
     }
    

    终端直接执行以下命令

    echo "module.exports = {
    
     // 可选类型
    
     types:[
    
       { value: 'feat',     name: 'feat:      新功能'},
    
       { value: 'fix',      name: 'fix:       修复'},
    
       { value: 'docs',     name: 'docs:      文档变更'},
    
       { value: 'style',    name: 'style:     代码格式(不影响代码运行的变动)'},
    
       { value: 'refactor', name: 'refactor:  重构(既不是增加feature),也不是修复bug'},
    
       { value: 'pref',     name: 'pref:      性能优化'},
    
       { value: 'test',     name: 'test:      增加测试'},
    
       { value: 'chore',    name: 'chore:     构建过程或辅助工具的变动'},
    
       { value: 'revert',   name: 'revert:    回退'},
    
       { value: 'build',    name: 'build:     打包'}
    
     ],
    
     // 步骤
    
     messages: {
    
       type: '请选择提交的类型;',
    
       customScope: '请输入修改的范围(可选)',
    
       subject: '请简要描述提交(必填)',
    
       body: '请输入详细描述(可选)',
    
       footer: '请选择要关闭的issue(可选)',
    
       confirmCommit: '确认要使用以上信息提交?(y/n)'
    
     },
    
     // 跳过步骤
    
     skip: ['body', 'footer'],
    
     // 默认长度
    
     subjectLimit: 72
    
    }" > .cz-config.js
    
    1. 安装配置commitlint
    pnpm i -D @commitlint/config-conventional @commitlint/cli
    

    配置commitlint,新建 commitlint.config.js 文件

    echo "module.exports = {
    
      extends: ['@commitlint/config-conventional'],
    
      // 定义规则类型
    
      rules: {
    
        // type 类型定义,表示 git 提交的 type 必须在以下类型范围内
    
        'type-enum': [
    
          2,
    
          'always',
    
          [
    
            'feat', // 新功能
    
            'fix', //  修复
    
            'docs', // 文档变更
    
            'style', // 代码格式(不影响代码运行的变动)
    
            'refactor', // 重构(既不是增加feature),也不是修复bug
    
            'pref', // 性能优化
    
            'test', // 增加测试
    
            'chore', // 构建过程或辅助工具的变动
    
            'revert', // 回退
    
            'build' // 打包
    
          ]
    
        ],
    
        // subject 大小写不做校验
    
        'subject-case': [0]
    
      }
    
    }" > commitlint.config.js
    
    1. 安装配置husky
    pnpm i husky -D
    
    npx husky install
    
    pnpm set-script prepare "husky install"
    
    pnpm run prepare
    

    添加 commitlint 的 hook 到 husky 中,commit-msg 时进行校验

    pnpx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
    

    相关文章

      网友评论

          本文标题:Git(Commitizen + husky + Git hoo

          本文链接:https://www.haomeiwen.com/subject/vpqpgdtx.html