前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >我是怎么写 Git Commit message 的?

我是怎么写 Git Commit message 的?

作者头像
新亮
发布2021-07-20 13:52:30
1K0
发布2021-07-20 13:52:30
举报
文章被收录于专栏:新亮笔记新亮笔记

文章目录:

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

作用

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

比如:

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

用的什么规范?

代码语言:javascript
复制
<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 时:

咱们看一下效果:

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

赶快去体验吧。

推荐阅读

参考资料

[1]

Commit message 和 Change log 编写指南: http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html

[2]

Git Commit Message Helper: https://plugins.jetbrains.com/plugin/13477-git-commit-message-helper

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-06-27,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 新亮笔记 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 作用
  • 用的什么规范?
    • type
      • scope
        • subject
          • body
            • footer
              • 参考文章
              • 用的什么辅助工具?
              • 推荐阅读
                • 参考资料
                领券
                问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档