如何标记或分类git commits [英] How to label or categorize git commits

查看:82
本文介绍了如何标记或分类git commits的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加到提交中的许多信息.此信息适用于自动和手动过程.示例包括团队的名称,状态(生成,开发,配置等)或票证编号.

I have a number of pieces of information that I would like to add to a commit. This information is for both automated and manual processes. Examples include a team's name, a status (generated, development, configuration, etc), or a ticket number.

是否可以将这些信息添加到提交中,还是必须像TICKET-1234:<HASH>那样标记?

Is there a way to add this information to the commits or do I have to tag akin to TICKET-1234:<HASH>?

推荐答案

有很多可用的选项:

  • 如果您只想为一个简短的,令人难忘的提交名称,您可以使用

  • If all you want is to short, memorable name for a commit, you can simply tag it using git tag. A tag object points to a commit and contains an additional message, and is itself named by a ref with a prefix of refs/tags/. By default, the fetch and push operations will not synchronise tags with a remote repository unless you pass --tags.

如果需要在提交创建时存储信息,则可以将其包含在类似RFC822的标头中的提交消息的底部:

If you need to store information at commit creation time, you can include it at the bottom of the the commit message in RFC822-like header:

Fixes: ticket #1234

git commit命令甚至提供了一个内置的--signoff选项,该选项会自动添加一个这样的标题.

The git commit command even provides a built-in --signoff option that adds one such header automatically.

如果您需要存储随时间变化的较长格式的信息,请查看

If you need to store longer-form information that changes over time, take a look at git notes:

添加,删除或读取附加在对象上的注释,而无需触摸对象本身.

Adds, removes, or reads notes attached to objects, without touching the objects themselves.

默认情况下,便笺将保存到refs/notes/commits并从中读取,但是此默认值可以被覆盖.请参阅下面的选项,配置和环境"部分.如果此引用不存在,则在第一次需要存储便笺时将自动创建该引用.

By default, notes are saved to and read from refs/notes/commits, but this default can be overridden. See the OPTIONS, CONFIGURATION, and ENVIRONMENT sections below. If this ref does not exist, it will be quietly created when it is first needed to store a note.

注释的典型用法是在不更改提交本身的情况下补充提交消息.注释可以由git log连同原始提交消息一起显示.为了将这些注释与存储在提交对象中的消息区分开来,这些注释像消息一样进行缩进,在未缩进的行之后写上"Notes(< refname>):"(或对于refs/notes/commits为"Notes:").

A typical use of notes is to supplement a commit message without changing the commit itself. Notes can be shown by git log along with the original commit message. To distinguish these notes from the message stored in the commit object, the notes are indented like the message, after an unindented line saying "Notes (<refname>):" (or "Notes:" for refs/notes/commits).

这样的标签,默认情况下,带有refs/notes/前缀的引用不会通过fetchpush操作进行同步.您还必须另外配置git来跟踪它们.

Like tags, by default refs with the refs/notes/ prefix are not synchronised by fetch and push operations. You'd have to additionally configure git to keep track of them.

这篇关于如何标记或分类git commits的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆