我是怎么写 Git Commit message 的?

简介: 我是怎么写 Git Commit message 的?

文章目录:

  • 作用
  • 用的什么规范?
  • type
  • scope
  • subject
  • body
  • footer
  • 参考文章
  • 用的什么辅助工具?
  • 推荐阅读


作用

编写格式化的 commit message 能够大大提高代码的维护效率。

比如:

  • 可以提供更多的历史信息,方便快速浏览;
  • 可以过滤某些 commit(比如文档改动),便于快速查找信息;
  • 可以直接从 commit 生成 Change log

用的什么规范?

<type>(<scope>): <subject>
// 空一行
<body>
// 空一行
<footer>

其中,Header 是必需的,Body 和 Footer 可以省略。

type

type 用于说明 commit 的类别。

  • feature A new feature
  • fix A bug fix
  • docs Documentation only changes
  • style Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • refactor A code change that neither fixes a bug nor adds a feature
  • perf A code change that improves performance
  • test Adding missing tests or correcting existing tests
  • build Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
  • ci Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
  • chore Other changes that don't modify src or test files
  • revert Reverts a previous commit

scope

scope 用于说明 commit 影响的范围,比如数据层、控制层、视图层、具体模块等等,视项目不同而不同。

subject

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

body

Body 部分是对本次 commit 的详细描述,可以分成多行。

footer

BREAKING CHANGE,用来描述当前 commit 与上一个版本不兼容的地方。

Issue,用来描述当前 commit 针对的某个issue。

参考文章

Commit message 和 Change log 编写指南[1]

用的什么辅助工具?

太教条了,太累... 给大家分享一个我使用的工具。

JetBrains IDE 插件,在 GoLandPhpStorm 中 都可以在插件市场搜索 Git Commit Message Helper

插件地址:Git Commit Message Helper[2]

安装后效果,在 git commit 时:

8bad4478455ce24402538fcee02fce4b.png

954bb43b5bc22e86ca3ffe274de249dd.png

咱们看一下效果:

ec9f15127da0f295e842ecbee09a9f61.png

b0effa17891e8c663d88cd7b6eab57a1.png

这时,点击 Commit 或 Commit and Push... 即可。

目录
相关文章
|
4月前
|
人工智能 缓存 开发工具
结合企业实践来规范你的Git commit(含插件使用指南)
结合企业实践来规范你的Git commit(含插件使用指南)
结合企业实践来规范你的Git commit(含插件使用指南)
|
30天前
|
开发工具 git
Git——commit的提交规范
Git——commit的提交规范
65 4
|
4月前
|
开发工具 git
Git Commit Msg
Git Commit Msg
63 0
|
4月前
|
JSON 开发工具 git
git rebase 合并当前分支的多个commit记录
git rebase 合并当前分支的多个commit记录
|
13天前
|
测试技术 持续交付 开发工具
[译] 为何每次 Git Commit 要尽可能小?
[译] 为何每次 Git Commit 要尽可能小?
|
14天前
|
Java 开发工具 Android开发
Android Studio利用Build.gradle导入Git commit ID、Git Branch、User等版本信息
本文介绍了在Android Studio项目中通过修改`build.gradle`脚本来自动获取并添加Git的commit ID、branch名称和用户信息到BuildConfig类中,从而实现在编译时将这些版本信息加入到APK中的方法。
28 0
|
2月前
|
前端开发 JavaScript 开发工具
前端优化之路:git commit 校验拦截
前面在git分支规范那篇文章里,介绍了commit提交规范,但是想要做到高效落地执行,就需要做些别的功课。
|
3月前
|
存储 开发工具 git
蓝易云 - git中,add到暂存区,commit且push之后,暂存区域里还有内容吗
所以,当你执行 `git add`,然后是 `git commit`,最后是 `git push`之后,暂存区是空的,除非你又执行了新的 `git add`命令来添加更多的更改。
32 1
|
3月前
|
开发工具 git
一文教你如何设置git commit模板规范
一文教你如何设置git commit模板规范
|
4月前
|
程序员 开发工具 git
【程序员英语 代码提交】C++工程师的代码提交艺术:git commit 时 精确表达与最佳实践
【程序员英语 代码提交】C++工程师的代码提交艺术:git commit 时 精确表达与最佳实践
159 1