重学Git

作者: 人猿Jim | 来源:发表于2021-05-23 15:55 被阅读0次
    siki from pixiv

    面对"你真的会XXX吗?"的灵魂拷问,还真没勇气斩钉截铁地说我会。
    最近一直维护的项目来了一个新的需求,把项目两个不同的版本(v1和v1.5)的功能整合到一个全新的版本(v2.0)。由于历史原因,git的main分支一直处于初始状态,基本无任何提交,大佬说,这个你来搞吧,然后就发给我一张图。

    Learn Git Branching
    思路瞬间清晰,溯源还是自己对git了解不够,于是就去玩了一下这个学习git的网站,发现确实不错,在这里分享给大家。

    这个项目叫做 Learn Git Branching,是一个寓教于乐的游戏项目,在github上有,一共有7个章节,一般把这7个章节都玩会了,git基本没问题了。

    git最佳实践:git flow

    git-flow
    git-flow中的merge

    git 规范工具 - husky commitlint commitizen

    利用git的husky工具可以规范git的提交规范,husky会在git的每个阶段提供钩子,用户可以利用提供的钩子去运行脚本,这时候配合commitlint就可以校验commit -msg的信息,再配合commitizen进行命令行引导式提交。

    npm i husky @commitlint/config-conventional @commitlint/cli commitizen -D
    npx husky install
    npx husky add .husky/commit-msg 'npx --no -- commitlint --edit "$1"'
    npm i commitizen commitlint/config-conventional -D
    
    // pakage.json
    {
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "lint": "eslint src",
        "lint:create": "eslint  --init",
        "commit": "cz"
      },
      "husky": {
        "hooks": {
          "pre-commit": "npm run lint && npm run test",
          "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
        }
      },
      "config": {
        "commitizen": {
          "path": "cz-conventional-changelog"
        }
      }
    }
    

    commitlint配置文件如下:

    // commitlint.config.js
    module.exports = {
      // extends: ['@commitlint/config-conventional'],
      rules: {
        'body-leading-blank': [1, 'always'],
        'footer-leading-blank': [1, 'always'],
        'header-max-length': [2, 'always', 72],
        'scope-case': [2, 'always', 'lower-case'],
        'subject-case': [1, 'never', ['sentence-case', 'start-case', 'pascal-case',
          'upper-case']],
        'subject-empty': [2, 'never'],
        'subject-full-stop': [2, 'never', '.'],
        'type-case': [2, 'always', 'lower-case'],
        'type-empty': [2, 'never'],
        'type-enum': [
          2,
          'always',
          ['build', 'chore', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor',
            'revert', 'style', 'test', 'improvement']
        ]
      }
    }
    
    // build:主要目的是修改项目构建系统(例如 glup,webpack,rollup 的配置等)的提交
    // ci:主要目的是修改项目继续集成流程(例如 Travis,Jenkins,GitLab CI,Circle等)的提交
    // docs:文档更新
    // feat:新增功能
    // merge:分支合并 Merge branch ? of ?
    // fix:bug 修复
    // perf:性能, 体验优化
    // refactor:重构代码(既没有新增功能,也没有修复 bug)
    // style:不影响程序逻辑的代码修改(修改空白字符,格式缩进,补全缺失的分号等,没有改变代码逻辑)
    // test:新增测试用例或是更新现有测试
    // revert:回滚某个更早之前的提交
    // chore:不属于以上类型的其他类型
    // git commit -m'feat: add commit valid'
    
    

    相关文章

      网友评论

          本文标题:重学Git

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