使用 Git 的开发者会使用 git commit 进行代码提交,也会使用 -m 提交commit message。对于一些个人开发者,也许他们会觉得“这是我个人的项目,不用太在意git commit message 的格式或者规范”。

但是对于一个团队或者在开源项目上工作的话,对于 commit message 的质量就会有比较高的要求了。一个好的 Git commit message 是向项目的其他参与者进行提交信息说明的十分重要的途径,对于开发这个人而言也在未来回顾提交信息的时候十分有意义。

有时候我们在旧项目上使用 git log 的时候会发现一堆杂乱的 commit messages。很难读懂当时提交这条 commit 的原因,增加或者修改了哪些内容。所以,一个“好”的 commit message 的重要性在于:

  • 一些项目需要严谨的开发过程,以及清楚的可追溯性,相关的责任人。 当这些项目出现问题时,重要的是要知道确切的原因:哪些代码更改不正确,哪些用户会受此问题影响,为什么当时修改了代码等等。
  • 好的代码值得被“认真”地分享。开发者应该不希望自己辛苦写了一个礼拜的代码提交为“add some new features”。我觉得这是对于开发者自己劳动成果的一种不尊重,至少需要体现出解决了哪些问题,哪里比较“酷”。

所以为了其他人,也为了自己,请认真对待 commit messages :)

参考下面的 commit (来自网络):

e5f4b49 Re-adding ConfigurationPostProcessorTests after its brief removal in r814. @Ignore-ing the testCglibClassesAreLoadedJustInTimeForEnhancement() method as it turns out this was one of the culprits in the recent build breakage. The classloader hacking causes subtle downstream effects, breaking unrelated tests. The test method is still useful, but should only be run on a manual basis to ensure CGLIB is not prematurely classloaded, and should not be run as part of the automated build.
2db0f12 fixed two build-breaking issues: + reverted ClassMetadataReadingVisitor to revision 794 + eliminated ConfigurationPostProcessorTests until further investigation determines why it causes downstream tests to fail (such as the seemingly unrelated ClassPathXmlApplicationContextTests)
147709f Tweaks to package-info.java files
22b25e0 Consolidated Util and MutableAnnotationUtils classes into existing AsmUtils
7f96f57 polishing

每次提交的内容从长度到格式都不同,写法像是“意识流”(非褒义)。在 github 上很多项目都是类似的提交格式,但是也有比较清晰准确的 commit messages,比如 Linux kernel,读者可以参考。

开发者可以自己制定一套 commit 的格式,也可以使用流行的一些格式。这里想要分享的是我个人和团队在使用的一种 commit convention: Angular。

概述

Angular 规定 commit message 的结构如下:

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

header + body(可选) + footer(可选)

header

header 包含三部分:type + scope + subject。比如,

feat(lang): add polish language

(1)type

  • feat:新功能(feature)
  • fix:修补bug
  • docs:文档(documentation)
  • style: 格式(不影响代码运行的变动)
  • refactor:重构(即不是新增功能,也不是修改bug的代码变动)
  • test:增加测试
  • chore:构建过程或辅助工具的变动

在 type 后面增加“!”代表重大的代码更改。

(2)scope

用于说明 commit 影响的范围,比如数据层、控制层、或者项目名称等等。

(3)subject

commit 的简短描述,不超过50个字符。

  • 以动词开头,使用第一人称现在时,比如change,而不是changedchanges
  • 第一个字母小写
  • 结尾不加句号(.

body (非必须)

body 是详细描述的信息,例如:

More detailed explanatory text, if necessary.  Wrap it to
about 72 characters or so. Further paragraphs come after blank lines. - Bullet points are okay, too
- Use a hanging indent

footer (非必须)

(1)不兼容变动

如果当前代码与上一个版本不兼容,则 Footer 部分以BREAKING CHANGE开头,后面是对变动的描述、以及变动理由和迁移方法。

(2)关闭 Issue

如果当前 commit 针对某个issue,那么可以在 Footer 部分关闭这个 issue 。

Closes #234

示例

Commit message with description and breaking change footer

feat: allow provided config object to extend other configs

BREAKING CHANGE: `extends` key in config file is now used for extending other config files

Commit message with ! to draw attention to breaking change

refactor!: drop support for Node 6

Commit message with both ! and BREAKING CHANGE footer

refactor!: drop support for Node 6

BREAKING CHANGE: refactor to use JavaScript features not available in Node 6.

Commit message with no body

docs: correct spelling of CHANGELOG

Commit message with scope

feat(lang): add polish language

Commit message with multi-paragraph body and multiple footers

fix: correct minor typos in code

see the issue for details

on typos fixed.

Reviewed-by: Z
Refs #133

参考

https://github.com/angular/angular/blob/22b96b9/CONTRIBUTING.md#-commit-message-guidelines

https://www.conventionalcommits.org/en/v1.0.0/

https://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html

发布于 2020-12-24 10:27

Git commit - Angular Convention的更多相关文章

  1. git & Angular git commit 规范

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

  2. 如何写好 Git commit messages

    导语:任何软件项目都是一个协作项目,它至少需要2个开发人员参与,当原始的开发人员将项目开发几个星期或者几个月之后,项目步入正规.不过他们或者后续的开发人员仍然需要经常提交一些代码去修复bug或者实现新 ...

  3. Git commit message和工作流规范

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

  4. git第四节----git commit message

    @git  commit message 什么是git commit message :git commit -m '每次提交时编辑的内容' git commit message的好处:      1 ...

  5. git使用总结(包含git commit message 和 changelog 工具的介绍)

    [git的配置] 1.配置用户名和邮箱: 分为全局配置和局部配置 --system 系统配置  --global 全局配置    --local 局部配置 Git读取时:优先从local>glo ...

  6. commitizen和cz-customizable配置git commit message

    起因 团队对提交的commit message格式有约定俗称的要求,但是没有一个统一的规范,导致大家提交的commit message或多或少不太一样.因此,需要一个工具来帮助大家统一commit m ...

  7. Git Commit 标准化

    1 前言Git Commit Message 应该清晰明了,要用精简的语言说明本次提交的目的,其主要作用是为了后续的搜索.版本的回滚.合并冲突的追溯等操作. 我们在开发时一直以来对 Git Commi ...

  8. git commit 、CHANGELOG 和版本发布的标准自动化

    一直以来,因为团队项目迭代节奏很快,每次发布的更新日志和版本更新都是通过人肉来完成的.有时候实在忙的团团转,对于手动的写这些更新信息就显得力不从心了.对于团队新来的小伙伴,有时候遇到些紧急情况,就更显 ...

  9. 优化 Git Commit Message

    目前很多项目都是通过 Git 进行管理的,Git 每次提交代码的过程中 提交说明 commit message 是必须的.但仅仅必须是不够的,好的提交说明可以帮助我们提高项目的整体质量. 作用与优点 ...

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

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

随机推荐

  1. Android复习(四)权限—>概览

    权限概述 许可 的目的是保护Android用户的隐私.Android应用必须获得访问敏感用户数据(例如联系人和SMS)以及某些系统功能(例如相机和互联网)的权限.根据功能的不同,系统可能会自动授予权限 ...

  2. OpenAI官方开源多智能体框架「Swarm」,并不是我想要的多智能体框架

    今天早上,OpenAI实施团队的 @shyamal在Github上开源了Swarm这个OpenAI官方的多智能体框架.不得不说,OpenAI官方下场,获得的社区影响就是不一样,在微信群.朋友圈里已经出 ...

  3. for-each循环陷阱

    for-each删除元素报错 public static void main(String[] args) { List<String> list = new ArrayList<& ...

  4. .NET云原生应用实践(三):连接到PostgreSQL数据库

    本章目标 实现基于PostgreSQL的SDAC(简单数据访问层) 将Stickers微服务切换到使用PostgreSQL SDAC 为什么选择PostgreSQL数据库? 其实并不一定要选择Post ...

  5. Vue生态工具组合

    文章目录 1.Vue版本 2.构建工具 3.包管理器 4.状态管理 5.http库 6.UI库 7.站点生成器 8.优质内容收录 vue生态工具多种多样,我们要如何选择并组合起来才最好呢.接下来给大家 ...

  6. You Shi Zai Wo

    Xuzhou is a place where there have been more than 50 large-scale battles from ancient times to the p ...

  7. Python网络爬虫之requests模块1

    Python网络爬虫之requests模块(1) 引入 Requests 唯一的一个非转基因的 Python HTTP 库,人类可以安全享用. 警告:非专业使用其他 HTTP 库会导致危险的副作用,包 ...

  8. Hibernate二级缓存 ---- 最佳实践

    2010年11月7号,立冬,星期天.北京外面风好大,躲在家里整理一下这篇文章,发出来与大家分享,对大家有帮助是我最高兴的事儿. 不要想当然的认为使用了Hibernate的二级缓存就一定能够提高应用程序 ...

  9. 从PipedInputStream/PipedOutputStream谈起

    本篇主要从分析PipeInputStrem和PipedOutputStream谈起.谈及软件设计的变化,以及如何将软件拆分.组合,适配-- 1 源代码分析 下面将详细分析PipedInputStrea ...

  10. golang之路由库gorilla/mux

    gorilla/mux是 gorilla Web 开发工具包中的路由管理库.gorilla Web 开发包是 Go 语言中辅助开发 Web 服务器的工具包.它包括 Web 服务器开发的各个方面, 有表 ...