美文网首页
规范你的Git Commit message

规范你的Git Commit message

作者: 姬艾思 | 来源:发表于2019-06-10 22:51 被阅读0次

    写在前面

    关于Git,大家想必都很熟悉,因为我们几乎每天都在重复着git addgit commitgit push等命令,自然也就留下很多“痕迹”,如果没有好的规范和工具来约束,可能就会出现以下情况:

    git_commit_error.png

    因此,规范和工具的重要性就体现出来了:

    关于 Git Commit message 的写法规社区有多种,本文采用的的 Angular 规范是目前使用最广的写法,比较合理和系统化,并且有配套的工具。

    推荐文章

    相关工具

    安装

    由于 commitizen 是基于 nodejs 的工具,所以首先需要安装 node 环境,具体不再赘述。

    全局
    yarn global add commitizen cz-conventional-emoji
    # OR
    # npm install --global commitizen cz-conventional-emoji
    
    # 设置全局默认适配器
    echo '{ "path": "cz-conventional-emoji" }' > ~/.czrc
    
    本地
    yarn add commitizen cz-conventional-emoji
    # OR
    # npm install --save-dev commitizen cz-conventional-emoji
    
    # 为你的项目设置默认适配器
    "config": {
        "commitizen": {
          "path": "./node_modules/cz-conventional-emoji"
        },
      }
    

    使用

    以后,凡是用到 git commit 命令,一律改为使用 git cz。这时,就会出现选项,用来生成符合格式的 Commit message(commitizen 与 emoji 结合)。如图:

    ? 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
      🔨  Refactor:               A code change that neither fixes a bug nor adds a feature
      🚀  Perf:                   A code change that improves performance
      ✅  Test:                   Adding tests.
    

    再看提交记录,是不是赏心悦目多了:


    git_commit_normal.png

    相关文章

      网友评论

          本文标题:规范你的Git Commit message

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