使用Git GUI结帐时,为什么没有列出我的标签? [英] Why isn't my tag listed when I checkout with Git GUI?

查看:111
本文介绍了使用Git GUI结帐时,为什么没有列出我的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地Git存储库,其中包含三个带注释的标签:v0.1.0v0.1.1v0.1.2.

I have a local Git repository which contains three annotated tags: v0.1.0, v0.1.1, and v0.1.2.

当我使用gitk(存储库→可视化母版的历史记录)查看项目的历史记录时,我可以看到分配给正确提交的每个标签.

When I view my project's history with gitk (Repository → Visualize master's history), I can see each tag assigned to the proper commit.

但是,当我尝试在Git GUI中签出我的标签( Branch→Checkout ...→标签)时,没有出现v0.1.1的标签.

However, when I try to checkout my tags in Git GUI (Branch → Checkout... → Tags), the tag for v0.1.1 doesn't appear.

当我去检查gitk中的每个标签时,我注意到标签详细信息略有不同. v0.1.0v0.1.2的详细信息将它们列为type commit,而v0.1.1的标签则被列为type tag.

When I went to check each tag in gitk, I noticed that the tag details were slightly different. The details for v0.1.0 and v0.1.2 listed them as type commit, while the tag for v0.1.1 was listed as type tag.

值得注意的是,我已经在该标签上重写了历史记录.为了修正标签说明中的拼写错误,我使用了 git tag <tag name> <tag name> -f -m "<new message>" .

It's worth noting that I've rewrote history on this tag. In order to fix a typo in my tag's description, I edited my tag message using git tag <tag name> <tag name> -f -m "<new message>".

为什么使用Git GUI签出时为什么看不到我的v0.1.1标签?为什么它显示为type tag?

Why can't I see my v0.1.1 tag when checking out with Git GUI? Why does it appear as type tag?

推荐答案

标记可以

Tags can point to any object in the git repository. If your tag type is "tag", then you have a tag pointing to another tag.

轻量标签不是对象;因此,它们没有自己的哈希ID,其他任何东西(如另一个标签)都无法指向它们.它们实际上只是指向某些对象的哈希ID的易于记忆的名称,比分支名称少一点.

Lightweight tags are not objects; thus, they have no hash ID of their own and nothing else (like another tag) can point to them. They are literally just easy-to-remember names pointing to some object's hash ID, a little less than a branch name.

但是,带注释的标签对象;它们就像提交一样,具有自己的消息,作者,创建日期以及最重要的是自己的哈希ID.这意味着有些混乱,它们可以被标记.

However, annotated tags are objects; they are like commits, with their own message, author, created date and, most importantly, their own hash ID. This means that, somewhat confusingly, they can be tagged.

果然,正如您在中的描述中所述,这正是发生的情况.根据如何重命名Git标签?中的建议,您执行了以下操作:

Sure enough, as you described in your comment, this is exactly what happened. Acting on the advice found in How do you rename a Git tag?, you did the following:

# avoid this...
git tag new old

由于old是带注释的标记,所以new标记的目标将是old标记,而不是其指向的提交.

Since old was an annotated tag, the target for the new tag will be the old tag, not the commit that it was pointing to.

如果要重命名带注释的标签,则应使用

If you want to rename an annotated tag, you should use

git tag -a new old^{}

old^{} 递归地取消引用标签,直到使用非标签对象找到 (在我们的示例中为一次提交),并将其用作new的目标对象.

进一步说明:假设您有一个仓库...哦,像这样: https://github.com/cyborgx37/sandbox/releases

To further illustrate: let's say you have a repo... oh, like this one: https://github.com/cyborgx37/sandbox/releases

在此仓库中,您将创建一个带注释的标签,如下所示:

In this repo you create an annotated tag like so:

> git tag -m "Version 0.1-beat" v0.1

哦,射击...您拼写错误的"beta",并且还决定将标签名称命名为v0.1-b.由于此内容已经发布,因此您决定执行理智的事情,然后直接创建一个新标签.遵循在互联网上找到的建议,您可以创建实际需要的标签(我将__tag附加在后面,原因将成为清除),方法是复制第一个标签:

Oh shoot... you misspelled "beta" and also you've decided that you want the tag name to be v0.1-b. Since this has already been published, you decide to do the sane thing and just create a new tag. Following advice you found on the internet, you create the tag you actually wanted (I appended __tag for reasons that will become clear) by copying the first tag:

> git tag -m "Version 0.1-beta" v0.1-b__tag v0.1

仅这些是带注释的标签,这意味着它们是实际的对象.因此,创建v0.1-b__tag时,实际上将其指向v0.1.您可以使用cat-fileshow清楚地看到结果.

Only, these are annotated tags, meaning they are actual objects. So when you created v0.1-b__tag, you actually pointed it at v0.1. You can see the result clearly using cat-file and show.

这是 v0.1 :

Here's v0.1:

> git cat-file -p v0.1

object 5cf4de319291579d4416da8e0eba8a2973f8b0cf
type commit
tag v0.1
tagger JDB <jd@domain.com> 1521058797 -0400

Version 0.1-beat

> git show v0.1

tag v0.1
Tagger: JDB <jd@domain.com>
Date:   Wed Mar 14 16:19:57 2018 -0400

Version 0.1-beat

commit 5cf4de319291579d4416da8e0eba8a2973f8b0cf (HEAD -> master, tag: v0.1-b__tag, tag: v0.1, origin/master)
Author: JDB <jd@domain.com>
Date:   Tue Oct 10 12:17:00 2017 -0400

    add gitignore

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..42d9955
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+file.txt

请注意, v0.1-b__tag 在目标类型和历史记录方面都不同:

Notice that v0.1-b__tag is different both in its target type as well as its history:

> git cat-file -p v0.1-b__tag

object 889b82584b2294486f4956dfea17b05e6224fb7f
type tag
tag v0.1-b__tag
tagger JDB <jd@domain.com> 1521059058 -0400

Version 0.1-beta

> git show v0.1-b__tag

tag v0.1-b__tag
Tagger: JDB <jd@domain.com>
Date:   Wed Mar 14 16:24:18 2018 -0400

Version 0.1-beta

tag v0.1
Tagger: JDB <jd@domain.com>
Date:   Wed Mar 14 16:19:57 2018 -0400

Version 0.1-beat

commit 5cf4de319291579d4416da8e0eba8a2973f8b0cf (HEAD -> master, tag: v0.1-b__tag, tag: v0.1, origin/master)
Author: JDB <jd@domain.com>
Date:   Tue Oct 10 12:17:00 2017 -0400

    add gitignore

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..42d9955
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+file.txt

显然,Git GUI对于可以检出哪些类型的对象(提交,而不是标签)相当有选择性,因此它忽略了指向另一个标签的标签.

Apparently Git GUI is rather selective about what types of objects can be checked out (commits, not tags), so it's ignoring your tag pointing at another tag.

如果使用我在上文中建议的git tag -a new old^{}方法,则可以避免戏剧化,并且首先获得想要的东西.我将创建一个新标签 v0.1-b__commit ,该标签指向v0.1的提交,而不是直接指向v0.1:

If you use the git tag -a new old^{} approach I suggested above, you can avoid the drama and get what you wanted in the first place. I'll create a new tag, v0.1-b__commit that points to v0.1's commit, rather than to v0.1 directly:

> git tag -m "Version 0.1-beta" v0.1-b__commit v0.1^{}

> git cat-file -p v0.1-b__commit

object 5cf4de319291579d4416da8e0eba8a2973f8b0cf
type commit
tag v0.1-b__commit
tagger JDB <jd@domain.com> 1521059039 -0400

Version 0.1-beta

> git show v0.1-b__commit

tag v0.1-b__commit
Tagger: JDB <jd@domain.com>
Date:   Wed Mar 14 16:23:59 2018 -0400

Version 0.1-beta

commit 5cf4de319291579d4416da8e0eba8a2973f8b0cf (HEAD -> master, tag: v0.1-b__tag, tag: v0.1-b__commit, tag: v0.1, origin/master)
Author: JDB <jd@domain.com>
Date:   Tue Oct 10 12:17:00 2017 -0400

    add gitignore

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..42d9955
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+file.txt

这篇关于使用Git GUI结帐时,为什么没有列出我的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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