当前位置: 首页 > news >正文

写出好的 commit message

 

为何要关注提交信息

  • 加快Reviewing Code的过程
  • 帮助我们写好release note
  • 5年后帮你快速想起来某个分支,tag或者 commit增加了什么功能,改变了哪些代码
  • 让其他的开发者在运行 git blame 的时候想跪谢
  • 总之一个好的提交信息,会帮助你提高项目的整体质量

基本要求

  • 第一行应该少于50个字。 随后是一个空行 第一行题目也可以写成:Fix issue #8976
  • 喜欢用 vim 的哥们把下面这行代码加入 .vimrc 文件中,来检查拼写和自动折行
autocmd Filetype gitcommit setlocal spell textwidth=72
  • 永远不在 git commit 上增加 -m <msg>--message=<msg> 参数,而单独写提交信息

一个不好的例子 git commit -m "Fix login bug"

一个推荐的 commit message 应该是这样:

Redirect user to the requested page after login

https://trello.com/path/to/relevant/card

Users were being redirected to the home page after login, which is less
useful than redirecting to the page they had originally requested before
being redirected to the login form.

* Store requested path in a session variable
* Redirect to the stored location after successfully logging in the user
  • 注释最好包含一个连接指向你们项目的 issue/story/card。一个完整的连接比一个 issue numbers 更好
  • 提交信息中包含一个简短的故事,能让别人更容易理解你的项目

注释要回答如下信息

为什么这次修改是必要的?

要告诉 Reviewers,你的提交包含什么改变。让他们更容易审核代码和忽略无关的改变。

如何解决的问题?

这可不是说技术细节。看下面的两个例子:

Introduce a red/black tree to increase search speed
Remove <troublesome gem X>, which was causing <specific description of issue introduced by gem>

如果你的修改特别明显,就可以忽略这个。

这些变化可能影响哪些地方?

这是你最需要回答的问题。因为它会帮你发现在某个 branch 或 commit 中的做了过多的改动。一个提交尽量只做1,2个变化。

你的团队应该有一个自己的行为规则,规定每个 commit 和 branch 最多能含有多少个功能修改。

小提示

  • 使用 fix, add, change 而不是 fixed, added, changed
  • 永远别忘了第2行是空行
  • Line break 来分割提交信息,让它在某些软件里面更容易读
  • 请将每次提交限定于完成一次逻辑功能。并且可能的话,适当地分解为多次小更新,以便每次小型提交都更易于理解。

例子

Fix bug where user can't signup.

[Bug #2873942]

Users were unable to register if they hadn't visited the plans
and pricing page because we expected that tracking
information to exist for the logs we create after a user
signs up.  I fixed this by adding a check to the logger
to ensure that if that information was not available
we weren't trying to write it.
Redirect user to the requested page after login

https://trello.com/path/to/relevant/card

Users were being redirected to the home page after login, which is less
useful than redirecting to the page they had originally requested before
being redirected to the login form.

* Store requested path in a session variable
* Redirect to the stored location after successfully logging in the user

本文参考阅读

  • A Note About Git Commit Messages
  • Writing good commit messages
  • Proper Git Commit Messages and an Elegant Git History
  • A Better Git Commit
  • 5 Useful Tips For A Better Commit Message
  • whatthecommit
  • 写好Git Commit信息的7个建议

 

相关文章:

  • 微软开发团队的DevOps实践启示
  • centos6.5环境下svn服务器和客户端配置实用详解
  • python 字典(dict)按键和值排序
  • url获取数据
  • 如何绘制caffe网络训练曲线
  • 日志分析系统——Hangout源码学习
  • spring boot 调试 - 热部署
  • 阿里云服务器Linux CentOS安装配置(零)目录
  • 数据结构 树 相关面试试题
  • zabbix Maintenance维护周期
  • [CentOs7]图形界面
  • Kafka问题排查(消费者自动关闭)
  • 手把手之STM32GPIO
  • iOS 读取plist 方法
  • json恶补
  • 10个确保微服务与容器安全的最佳实践
  • centos安装java运行环境jdk+tomcat
  • C语言笔记(第一章:C语言编程)
  • HomeBrew常规使用教程
  • java多线程
  • leetcode-27. Remove Element
  • LintCode 31. partitionArray 数组划分
  • Mysql数据库的条件查询语句
  • SQLServer之创建显式事务
  • 不发不行!Netty集成文字图片聊天室外加TCP/IP软硬件通信
  • 电商搜索引擎的架构设计和性能优化
  • 让你的分享飞起来——极光推出社会化分享组件
  • 深入浅出webpack学习(1)--核心概念
  • 实习面试笔记
  • 通过git安装npm私有模块
  • 智能合约Solidity教程-事件和日志(一)
  • #【QT 5 调试软件后,发布相关:软件生成exe文件 + 文件打包】
  • (5)STL算法之复制
  • (二)Linux——Linux常用指令
  • (附源码)springboot社区居家养老互助服务管理平台 毕业设计 062027
  • (每日持续更新)信息系统项目管理(第四版)(高级项目管理)考试重点整理 第13章 项目资源管理(七)
  • (深入.Net平台的软件系统分层开发).第一章.上机练习.20170424
  • (学习日记)2024.03.25:UCOSIII第二十二节:系统启动流程详解
  • (已解决)vue+element-ui实现个人中心,仿照原神
  • (转)http-server应用
  • (转)winform之ListView
  • (最全解法)输入一个整数,输出该数二进制表示中1的个数。
  • .Net Core 中间件验签
  • .net Signalr 使用笔记
  • .net 调用php,php 调用.net com组件 --
  • .NET/C# 避免调试器不小心提前计算本应延迟计算的值
  • .NET高级面试指南专题十一【 设计模式介绍,为什么要用设计模式】
  • .NET企业级应用架构设计系列之结尾篇
  • .NET设计模式(2):单件模式(Singleton Pattern)
  • .NET中的Exception处理(C#)
  • .net最好用的JSON类Newtonsoft.Json获取多级数据SelectToken
  • /run/containerd/containerd.sock connect: connection refused
  • /ThinkPHP/Library/Think/Storage/Driver/File.class.php  LINE: 48
  • [ 网络基础篇 ] MAP 迈普交换机常用命令详解
  • [Android]使用Android打包Unity工程