你如何注解一个分支? [英] How do you annotate a branch?

查看:134
本文介绍了你如何注解一个分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以注释一个分支?能够做到这样的事情会很好:

 
$ git notes add branch-name -m'这个分支用于任何'

但这当然不是非常有帮助,因为该注释适用于分支的当前头部而不是分支本身。

一个简单的解决方法是在存储库中放置一个README.branch名称,但这看起来很笨拙。稍微更优雅的是有一个孤立的分支只包含README.branch-names。我正在寻找一种方法来记录分支的用途,而不仅仅是将它放在分支的第一次提交的提交消息中。我把第一个放在引号中,因为它并不总是清楚这是什么意思,这就是将讨论放在提交信息中不方便的原因。通常很难找到记录这样的消息的提交。

解决方案

这将是一个完全不同于 git note ,但您可以使用 git config 来实现此功能。



$ git config branch。< branch-name> .note'这是这个分支的用途'



这可以是别名,使界面更简单(我猜这可以改善,但这是我使用):



$ git配置alias.branch-note'!git config branch。$(git symbolic-ref --short HEAD).note $(if [$#-gt 0]; then $ 1; fi)'



这允许你像这样设置分支注释(确保你引用注释):

$ git branch-note'这就是这个分支的用途'



然后你可以像这样检索当前分支注释:

  $ git分支注释
这是什么作为一个额外的好处,配置在分支下定义的条目。 < branch-name> 命名空间将遵循分支重命名,并在以后删除分支时自动清除。这些多余的配置条目只有在分支存在时才会持续存在,这时它们将被自动删除。



这种方法的缺点是只能存储一个每个分支的笔记。随后的带有参数的分行票据调用将覆盖先前的分行票据。你也没有得到将消息存储在可追踪的git对象中的好处,但也许这足以满足你的需要。


Is there any way to annotate a branch? It would be nice to be able to do something like:

$ git notes add branch-name -m 'This branch is for whatever'

but that of course is not terribly helpful, since the note applies to the current head of the branch rather than the branch itself.

An easy workaround is to drop a README.branch-name in the repository, but that seems clumsy. Slightly more elegant is to have an orphaned branch containing nothing but README.branch-names. I'm looking for a way to record what the purpose of the branch is other than just putting it in the commit message for the "first" commit of the branch. I put "first" in quotes because it's not always clear what is meant by that, which is the reason it is inconvenient to put the discussion in a commit message. It's often difficult to find the commit in which such a message is recorded.

解决方案

This would be a totally different approach than git note but you could use git config for this functionality.

$ git config branch.<branch-name>.note 'This is what this branch is for'

This can be aliased to make the interface simpler (I'm guessing this can be improved but this is what I use):

$ git config alias.branch-note '!git config branch.$(git symbolic-ref --short HEAD).note $( if [ $# -gt 0 ]; then $1; fi)'

This allows you to set the branch note like so (make sure you quote the note):

$ git branch-note 'This is what this branch is for'

You can then retrieve the current branches note like this:

$ git branch-note
This is what this branch is for

As an added benefit, config entries defined under the branch.<branch-name> namespace will follow branch renames and be automatically cleaned up if you delete the branch later. These superfluous config entries will only persist as long as the branch exists, at which time they will be automatically deleted.

A downside to this approach is that you can only store one "note" per branch. Subsequent branch-note calls with an argument will overwrite the previous branch-note. You also don't get the benefit of storing the message in a trackable git object but maybe it will suffice for your purposes.

这篇关于你如何注解一个分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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