git:有没有像每个分支标签? [英] git: Is there something like per-branch tags?

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

问题描述

我有一些历史重写要做,为此我想保留原始树的完整性。然而,重写的树应该复制之前使用的标签。有没有比例如手动选项更少在分支名称前添加标签名?

解决方案

不,git中没有任何每分支标签。所有分支和标签都只是Git中的参考类型; ref只是一个指向修订历史记录中特定修订版的名称。例如,如果你有 devel master 分支,并且 v1.0 v2.0 标记,引用将如下所示:

 
refs / heads / devel - > *
/ \
* * < - refs / heads / master
| |
* *
\ /
*< - refs / tags / v2.0
|
*
|
*< - refs / tags / v1.0
|
*

正如您所看到的,没有任何东西将这些标签绑定到任何分支。实际上,所有这些标签都包含在 master devel 分支中。通过查看 .git 回购库中的内容,可以看到实际上没有更多的标签结构。它只是一个包含引用 .git / refs 中的提交的SHA-1的文件,或者是 .git / packed-refs (标签常常在 packed-refs 中,因为它们不会经常更改,而分支通常是 git中的独立文件所以如果你想重写历史并保留旧的标签,你将不得不重写你的标签名称。正如sehe指出的,这是通过使用 git filter-branch --tag-name-filter


I have some history rewriting to do for which I'd like to keep my original tree intact for now. The rewritten tree should however copy the tags previously used as well. Is there any less manual option than e.g. prepending tag names with the branch name?

解决方案

No, there is nothing like a per-branch tag in git. All branches and tags are just kinds of refs in Git; a ref is just a name that points to a particular revision in the revision history. For instance, if you have devel and master branches, and v1.0 and v2.0 tags, the references would look something like this:

refs/heads/devel ->  *
                    / \
                   *   * <- refs/heads/master
                   |   |
                   *   *
                    \ /
                     * <- refs/tags/v2.0
                     |
                     *
                     |
                     * <- refs/tags/v1.0
                     |
                     *

As you can see, there's nothing tying those tags to any branches; in fact, all of those tags are contained in both the master and devel branches. By looking inside your .git repo, you can see that there is really no more structure to a tag than that; it is just a file containing a SHA-1 referencing a commit within .git/refs, or a line in .git/packed-refs (tags will frequently be in packed-refs because they don't change often, while branches will usually be separate files within git/refs).

So if you want to rewrite history, and preserve the old tags, you will have to rewrite your tag names. As sehe points out, this is done using git filter-branch --tag-name-filter.

这篇关于git:有没有像每个分支标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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