规范git commit 提交的小技巧之一

398 阅读2分钟

我们在提交Git的时候,都是比较随意的,协同工作的时候不利于留下历史记录和维护,对于问题的追踪和版本的迭代不友好。基于这个出发点,对commit提交进行一个约定~~

基本思想

1、把commit提交的内容进行分类。

类似于gitflow,约定出提交的种类规范化,杜绝随意性。

2、约定规范

人为制定第一步说的规范化

3、规范配置化

形成配置文件

实现方案

使用git开源库“git-cz”替代git commit功能

改造步骤

  1. 全局引入git-cz库
npm install -g git-cz
  1. 项目新建changelog.config.js配置文件

例如:

/*
 * @Author: your name
 * @Date: 2020-03-09 17:06:22
 * @LastEditTime: 2020-03-09 18:00:02
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \offline-store\changelog.config.js
 */
module.exports = {
  'disableEmoji': false,
  'list': [
    '测试',
    '新功能',
    'bug修复',
    '临时任务',
    '说明注释',
    '代码重构',
    '样式更新',
    '环境构建',
    '性能优化',
    '线上问题修复'
  ],
  'maxMessageLength': 100,
  'minMessageLength': 3,
  'questions': [
    'type',
    'scope',
    'subject',
    'body',
    'breaking',
    'issues',
    'lerna'
  ],
  'scopes': [],
  'types': {
    '临时任务': {
      'description': 'Build process or auxiliary tool changes',
      'emoji': '☏',
      'value': '临时任务'
    },
    '环境构建': {
      'description': 'CI related changes',
      'emoji': '✍',
      'value': '环境构建'
    },
    '说明注释': {
      'description': 'Documentation only changes',
      'emoji': '✏️',
      'value': '说明注释'
    },
    '新功能': {
      'description': 'A new feature',
      'emoji': '⚡️',
      'value': '新功能'
    },
    'bug修复': {
      'description': 'A bug fix',
      'emoji': '☺',
      'value': 'bug修复'
    },
    '性能优化': {
      'description': 'A code change that improves performance',
      'emoji': '☼',
      'value': '性能优化'
    },
    '代码重构': {
      'description': 'A code change that neither fixes a bug or adds a feature',
      'emoji': '♛',
      'value': '代码重构'
    },
    '线上问题修复': {
      'description': 'Create a release commit',
      'emoji': 'ઇଓ',
      'value': '线上问题修复'
    },
    '样式更新': {
      'description': 'Markup, white-space, formatting, missing semi-colons...',
      'emoji': '♬',
      'value': '样式更新'
    },
    '代码合并': {
      'description': 'take a merge',
      'emoji': '❆',
      'value': '代码合并'
    },
    '测试': {
      'description': 'Adding missing tests',
      'emoji': '۞',
      'value': '测试'
    }
  }
};
  1. 提交变更不再使用git commit
git cz