美文网首页
Git提交消息

Git提交消息

作者: HelenYin | 来源:发表于2017-10-30 22:48 被阅读0次
如何给git commit 添加一段简短且有意义的描述

每一个commit应该包括以下几部分:header,body,footer
header包括type,scope,subject

<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>

type

type是以下的几个:

  • feat: 新功能
  • fix: 修复bug
  • docs: 只有文档改变
  • style: 并没有影响代码的意义(空格,去掉分号,格式的修改等)
  • refactor: 代码的修改并没有修改bug,也没有添加新功能
  • perf: 代码的修改提高的性能
  • test: 添加测试
  • chore: 构建过程或构建工具的改变(并没有生产环境代码的改变)

Scope

scope是可选的,用来说明本次提交影响的范围(在angular的代码提交中会写这些$location, $browser, $compile, $rootScope, ngHref, ngClick, ngView

Subject

Subject最多50个字

  • 使用命令式
  • 首字母大写
  • 不要用“.”结尾

Body


并不是所有的commit都需要body,只有当这个commit需要一些说明的时候才添加body。有时候一行Subject来说明足以。body中备注代码改动的什么,以及为什么要这样改(而不是怎么改的)

下面是一个示范:

commit eb0b56b19017ab5c16c745e6da39c53126924ed6
Author: Pieter Wuille <pieter.wuille@gmail.com>
Date:   Fri Aug 1 22:57:55 2014 +0200

   Simplify serialize.h's exception handling

   Remove the 'state' and 'exceptmask' from serialize.h's stream
   implementations, as well as related methods.

   As exceptmask always included 'failbit', and setstate was always
   called with bits = failbit, all it did was immediately raise an
   exception. Get rid of those variables, and replace the setstate
   with direct exception throwing (which also removes some dead
   code).

   As a result, good() is never reached after a failure (there are
   only 2 calls, one of which is in tests), and can just be replaced
   by !eof().

   fail(), clear(n) and exceptions() are just never called. Delete
   them.

需要注意:在写body的时候,保证每行最多只有72个字符

Footer


footer是可选的,可以用来跟踪issue的id,比如这个commit是用来关闭了某个issue:

Closes #123

Commitizen


可以使用commitizen来帮助团队规范化整个流程,与npm scripts配合自动化整个流程。

首先,本地安装Commitizen

npm install commitizen --save-dev

然后安装cz-conventional-changelogcz-conventional-changelog是一个适配器,用来适配不同代码的提交。这里我们项目中使用的是angular的代码适配器

npm install cz-conventional-changelog --save-dev

然后在package.json的root添加

"config": {
    "commitizen": {
      "path": "cz-conventional-changelog"
    }
  }

现在便可以使用Commitizen来提交git commit,具体用法就是,在git commit的时候改为使用git-cz.这里我把命令写进npm script中

"scripts": {
    "commit": "git-cz"
  }

然后我们在提交代码时先git add -A,然后npm run commit,就会在命令行提示输入header(type, scope, subject), body, footer

相关文章

  • Git提交消息

    如何给git commit 添加一段简短且有意义的描述 每一个commit应该包括以下几部分:header,bod...

  • 2018-04-19

    稀里糊涂用了几个git命令,本地代码竟然消息不见了,还要执行过git add .和git commit 提交过本地...

  • Git基本指令

    unix思想:没有消息就是好消息,正确提交无反馈。 要提交修改得先用add指令添加到暂存区 基本指令 git in...

  • git 查看信息

    浏览本地仓库的所有写操作 1 .git reflog 查看所有commit消息 1 .git log 搜索提交历史...

  • git log --grep 用法

    使用方法:git log 支持正则表达式搜索提交消息 git log --grep 使用场景:比...

  • GIT命令

    新建路径: git clone 提交修改: git add . 本地提交: git comm...

  • Windows 下 git-bash log 乱码的原因及方案

    前言 在 Windows 下用 git log 来看历史提交记录时,如果提交消息是中文,有可能就会乱码。为什么说有...

  • 关于Git

    首次提交5条 git init .......git 重复提交3条 git add . git commit -m...

  • git常用命令

    git add . git commit -m "message"提交,其中message是提交的信息。 git ...

  • git 常用的命令

    git status 检测状态 git add . 提交的代码显示 git commit -m "备注" 提交...

网友评论

      本文标题:Git提交消息

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