• 如何写好git commit log


    如何写好git commit log

    一、git commit message格式
    <type>(<scope>): <subject>
    <BLANK LINE>
    <body>
    <BLANK LINE>
    <footer>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    我们通过 git commit 命令带出的 vim 界面填写的最终结果应该类似如上这个结构, 大致分为三个部分(使用空行分割):

    • 标题行: 必填, 描述主要修改类型和内容
    • 主题内容: 描述为什么修改, 做了什么样的修改, 以及开发的思路等等
    • 页脚注释: 放 Breaking Changes 或 Closed Issues

    分别由如下部分构成:

    type: commit 的类型
    feat: 新特性
    fix: 修改问题
    refactor: 代码重构
    docs: 文档修改
    style: 代码格式修改, 注意不是 css 修改
    test: 测试用例修改
    chore: 其他修改, 比如构建流程, 依赖管理
    scope: commit 影响的范围, 比如: route, component, utils, build...
    subject: commit 的概述, 建议符合 50/72 formatting
    body: commit 具体修改内容, 可以分为多行, 建议符合 50/72 formatting
    footer: 一些备注, 通常是 BREAKING CHANGE 或修复的 bug 的链接.

    二、使用终端工具 commitizen/cz-cli + commitizen/cz-conventional-changelog一步解决提交信息
    1.在根目录下修改或添加 .gitconfig文件

    向其中添加内容

    [commit]
    template = ~/.gitmessage
    
    • 1
    • 2
    2.新建 ~/.gitmessage 内容可以如下:
    # head: <type>(<scope>): <subject>
    # - type: feat, fix, docs, style, refactor, test, chore
    # - scope: can be empty (eg. if the change is a global or difficult to assign to a single component)
    # - subject: start with verb (such as 'change'), 50-character line
    #
    # body: 72-character wrapped. This should answer:
    # * Why was this change necessary?
    # * How does it address the problem?
    # * Are there any side effects?
    #
    # footer: 
    # - Include a link to the ticket, if any.
    # - BREAKING CHANGE
    #
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    3.Commitizen: 替代你的 git commit

    安装

    npm install -D commitizen cz-conventional-changelog
    
    • 1

    package.json中配置:

    "script": {
        ...,
        "commit": "git-cz",
    },
     "config": {
        "commitizen": {
          "path": "node_modules/cz-conventional-changelog"
        }
      }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    4.提交代码时使用npm run commit代替git commit
  • 相关阅读:
    Java集合--Collection、Map、List、Set、Iterator、Collections工具类
    [二叉树&单调栈/递归] LeetCode 654. 最大二叉树(笛卡尔树)
    服装公司事务/办理流程是如何办理的?
    【剑指offer】17.打印从1到最大的n位数
    产品推荐 - 基于Xilinx Kintex-7 XC7K160T/325T/410T打造的水星Mercury+ KX2核心板
    Kylin 使用心得
    python 之yaml库使用总结
    『现学现忘』Docker基础 — 23、使用Docker安装Tomcat
    基于Seata的分布式事务方案
    Spring Boot 自定义配置元数据
  • 原文地址:https://blog.csdn.net/katherin_wanzi/article/details/127447673