https://www.yuque.com/fe9/basic/nruxq8#6c228def 语雀平台

制定一个 git commit 信息的提交规范是开发团队工作流必不可少的环节。试想一下,如果查看主分支上的历史库也就是你查看 git log 的时候,打印出来的信息杂乱无章的话,如果代码遇到问题,可能需要很大的精力与成本来查找到导致问题的代码提交,所以团队需要制定规范来引导成员编写规范的 commit 信息。

接下来的 commit 信息规范参考了 angularjs 团队的开发者指引与笔者的工作团队进行总结,读者如有需要可以以此为基础增加或修改成为自己团队的 commit 规范的一部分。

提交信息基本模板

如果 commit 信息都按照一定的模式进行提交,那么我们就会很容易找到自己想要的信息,模板参考如下:

<type>(<scope>): <subject> [<ISSUE_ID>]

<body>

<footer>

commit 信息包括三个字段: type (必需), scope(可选) 和 subject(必需)。

  1. type。type 是用于说明该 commit 的类型的,一般我们会规定 type 的类型如下:
  • feat: 新功能(feature)
  • fix: 修复 bug
  • docs: 文档(documents)
  • style: 代码格式(不影响代码运行的格式变动,注意不是指 CSS 的修改)
  • refactor: 重构(既不是新增功能,也不是修改 bug 的代码变动)
  • test: 提交测试代码(单元测试,集成测试等)
  • chore: 构建或辅助工具的变动
  • misc: 一些未归类或不知道将它归类到什么方面的提交
  1. scope。scope 说明 commit 影响的范围,比如数据层,控制层,视图层等等,这个需要视具体场景与项目的不同而灵活变动
  2. subject。subject 是对于该 commit 目的的简短描述
  • 使用第一人称现在时的动词开头,比如 modify 而不是 modified 或 modifies
  • 首字母小写,并且结尾不加句号
  1. ISSUEE_ID。这个与公司的需求管理与项目管理有关,假设你的项目放在 github 上,你的需求或者 bug 修复可能会有对应的 issues 记录,你可以加到你的 commit 信息中如 issue-37938634

body 其实就是 subject 的详细说明,而 footer 中你可以填写相关的需求管理 issues id。

在企业中一般会对团队中要做的事情与需求开发使用一个软件进行管理,好处是可以让代码与对应的用户故事(story)或者需求,bug 进行关联,便于管理,类似的方案有 github,gitlab,tracker,JIRA 等等,比如在网易某些团队中就会使用 JIRA 加上 gitlab 来进行团队管理。

commit message 的规范性是很重要的,对于自己养成良好的编程习惯很有帮助,但是没有必要强制完全遵循开源团队的规范,毕竟每个团队与个人的情况不同,博采众长即可,当然你也可以使用像 commitlint 这样的校验工具从工具层面上来强制执行某些规范,这里就不展开讲了,有兴趣的读者可以查阅相关资料并使用到自己团队的实践中。

https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration

commit.template

If you set this to the path of a file on your system, Git will use that file as the default initial message when you commit. The value in creating a custom commit template is that you can use it to remind yourself (or others) of the proper format and style when creating a commit message.

For instance, consider a template file at ~/.gitmessage.txt that looks like this:

Subject line (try to keep under 50 characters)

Multi-line description of commit,
feel free to be detailed. [Ticket: X]

Note how this commit template reminds the committer to keep the subject line short (for the sake of git log --oneline output), to add further detail under that, and to refer to an issue or bug tracker ticket number if one exists.

To tell Git to use it as the default message that appears in your editor when you run git commit, set the commit.template configuration value:

$ git config --global commit.template ~/.gitmessage.txt
$ git commit

Then, your editor will open to something like this for your placeholder commit message when you commit:

Subject line (try to keep under 50 characters)

Multi-line description of commit,
feel free to be detailed. [Ticket: X]
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: lib/test.rb
#
~
~
".git/COMMIT_EDITMSG" 14L, 297C

If your team has a commit-message policy, then putting a template for that policy on your system and configuring Git to use it by default can help increase the chance of that policy being followed regularly.

Git Commit Msg

Create A Custom Git Commit Template

git commit的规范的更多相关文章

  1. Git Commit Message 规范

    今天来说说团队开发中,对于 Git commit message 规范问题. 社区上有各种 Commit message 的规范,本文介绍 Angular 规范,目前使用较广,比较合理和系统化,并且有 ...

  2. Git Commit 提交规范

    写好 Commit message 好处多多: 1.统一团队Git commit 日志风格 2.方便日后 Reviewing Code 3.帮助我们写好 Changelog 4.能很好的提升项目整体质 ...

  3. 自家公司关于git commit 的规范

    代码提交的commit info提个建议,fix的issue是哪个issue?都要有明确的链接.推荐方式:1.建立issue,说明问题的背景和原因.http://git.startdt.net/pay ...

  4. 规范git commit提交记录和版本发布记录

    在开发过程中我们一般都会用到git管理代码,在git commit提交代码时我们一般对git commit message随便写点简单的描述,可是随着项目参与人数的增多,发现提交的commit记录越来 ...

  5. 如何规范git commit提交

    相信很多人使用SVN.Git等版本控制工具时候都会觉得每次提交都要写一个注释有什么用啊?好麻烦,所以我每次都是随便写个数字就提交了,但是慢慢的我就发现了,如果项目长期维护或者修改很久之前的项目,没有一 ...

  6. Git commit message和工作流规范

    目的 统一团队Git commit日志标准,便于后续代码review,版本发布以及日志自动化生成等等. 统一团队的Git工作流,包括分支使用.tag规范.issue等 Git commit日志参考案例 ...

  7. git & Angular git commit 规范

    git & Angular git commit 规范 https://github.com/angular/angular/commits/master https://github.com ...

  8. git commit规范工具

    npm install -g commitizen commitizen init cz-conventional-changelog --save --save-exact 以后,凡是用到git c ...

  9. Git Commit Template 提交模板

    多人协作开发一个项目时,版本控制工具是少不了的,git是linux 内核开发时引入的一个优秀代码管理工具,利用它能很好使团队协作完成一个项目.为了规范团队的代码提交,也方便出版本时的release n ...

随机推荐

  1. 【jdk源码学习】HashMap

    package com.emsn.crazyjdk.java.util; /** * “人”类,重写了equals和hashcode方法...,以id来区分不同的人,你懂的... * * @autho ...

  2. LeetCode——Kth Largest Element in an Array

    Description: Find the kth largest element in an unsorted array. Note that it is the kth largest elem ...

  3. 使用Eclipse(以及intellij IDEA)配合JDWP对服务器上部署的代码进行调试

    今天遇到了一个问题:同样的代码,在服务器上跑的时候会报空指针异常,但是在本地是没有问题的,看服务器上打印的日志只能看到异常信息,不能准确地定位到出问题的代码,于是就搜索了一下远程调试.结果还真的可以在 ...

  4. mysql动态sql 整理多个字段

    原始表: 整理后的表: 方案一(动态sql): BEGIN #Routine body goes here... DECLARE v1 ); DECLARE v2 ); #DECLARE v3 VAR ...

  5. Linux系统下 Supervisor 安装搭建

    在 web 应用部署到线上后,需要保证应用一直处于运行状态,在遇到程序异常.报错等情况,导致 web 应用终止时,需要保证程序可以立刻重启,继续提供服务. 所以,就需要一个工具,时刻监控 web 应用 ...

  6. thinkphp中 volist循环的 mod取值的问题

    <ul> <volist name="data" id="arr" key="k" mod="2"&g ...

  7. 大话https演化过程(对称加密、非对称加密、公钥、私钥、数字签名、数字证书)

    大话https演化过程(包括概念:对称加密.非对称加密.公钥.私钥.数字签名.数字证书.https访问全过程)   在网络上发送数据是非常不安全的,非常容易被劫持或是被篡改,所以每次定向发送数据你都可 ...

  8. 代码处理 iOS 的横竖屏旋转

    一.监听屏幕旋转方向 在处理iOS横竖屏时,经常会和UIDeviceOrientation.UIInterfaceOrientation和UIInterfaceOrientationMask这三个枚举 ...

  9. c primer plus(五版)编程练习-第七章编程练习

    1.编写一个程序.该程序读取输入直到遇到#字符,然后报告读取的空格数目.读取的换行符数目以及读取的所有其他字符数目. #include<stdio.h> #include<ctype ...

  10. (转)《SSO CAS单点系列》之 15分钟让你了解SSO技术到底是个什么鬼!

    Web应用系统的演化总是从简单到复杂,从单功能到多功能模块再到多子系统方向发展. .当前的大中型Web互联网应用基本都是多系统组成的应用群,由多个web系统协同为用户提供服务. 多系统应用群,必然意味 ...