列出 git-ls-remote 时为什么标签名称后面有“^{}”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15472107/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
When listing git-ls-remote why there's "^{}" after the tag name?
提问by Andris
When I run git ls-remote
in the work tree, the command outputs a list of revisions in the origin repo. For some reason I get 2 revisions with every tag and for the second revision of the same tag, the tag name includes ^{}
当我git ls-remote
在工作树中运行时,该命令会输出原始存储库中的修订列表。出于某种原因,我得到了每个标签的 2 个修订版本,对于同一标签的第二个修订版本,标签名称包括^{}
git ls-remote
From [email protected]:andris9/zzzzzz.git
d69e66d7c915b9682618b7f304b80cc0ae4c7809 HEAD
....
bb944682f7f65272137de74ed18605e49257356c refs/tags/v0.1.6
771a930dc0ba86769d6862bc4dc100acc50170fa refs/tags/v0.1.6^{}
a72251d945353a360087eb78ee75287c38a1c0e6 refs/tags/v0.1.7
d69e66d7c915b9682618b7f304b80cc0ae4c7809 refs/tags/v0.1.7^{}
I create tags with
我创建标签
git tag -a v0.1.8 -m "tag message"
git push --tags
From the examples of git-ls-remote
man pagethere are no such duplicate tags, so maybe I'm doing something wrong?
从git-ls-remote
手册页的例子来看,没有这样的重复标签,所以也许我做错了什么?
回答by Tuxdude
There are 2 types of tags - lightweight
and annotated
. Lightweight tags are merely refs that point to some object whereas annotated tags are a separate git object by themselves, and store a lot more information like author, committer, a commit message, etc.
有两种类型的标签 -lightweight
和annotated
. 轻量级标签只是指向某个对象的引用,而带注释的标签本身就是一个单独的 git 对象,并存储更多信息,如作者、提交者、提交消息等。
When you used git tag -a
to create a tag, git would have created an annotated tag for you.
当您过去git tag -a
创建标签时,git 会为您创建一个带注释的标签。
The ^{}
is the syntax used to dereference a tag. It is described in gitrevisions.
这^{}
是用于取消引用标记的语法。它在gitrevisions 中有描述。
When used with tag objects, git would recursively dereference the tag until it finds a non-tag object.
When used with non-tag objects, it doesn't do anything and is equivalent to skipping the
^{}
当与标签对象一起使用时,git 会递归地取消引用标签,直到找到一个非标签对象。
当与非标签对象一起使用时,它不做任何事情,相当于跳过
^{}
The refs/tags/v0.1.6
ref in your repository points to the tag object bb944682f7f65272137de74ed18605e49257356c
, which in turn points to 771a930dc0ba86769d6862bc4dc100acc50170fa
(a non-tag object) which I'm guesssing is storing the commit information when you created the tag.
refs/tags/v0.1.6
您存储库中的ref 指向 tag object bb944682f7f65272137de74ed18605e49257356c
,它又指向771a930dc0ba86769d6862bc4dc100acc50170fa
(一个非标记对象),我猜这是在您创建标记时存储提交信息。
So when you do refs/tags/v0.1.6^{}
, git is going to dereference the tag and resolve it to 771a930dc0ba86769d6862bc4dc100acc50170fa
- the non-tag object.
因此,当您这样做时refs/tags/v0.1.6^{}
,git 将取消引用标记并将其解析为771a930dc0ba86769d6862bc4dc100acc50170fa
- 非标记对象。
There is also a git show-ref
command that can be used to list only tags, and optionally dereference as follows, and in your case should produce the following output:
还有一个git show-ref
命令可用于仅列出标签,并可选择取消引用如下,在您的情况下应产生以下输出:
$ git show-ref --tags
bb944682f7f65272137de74ed18605e49257356c refs/tags/v0.1.6
a72251d945353a360087eb78ee75287c38a1c0e6 refs/tags/v0.1.7
$ git show-ref --tags --dereference
bb944682f7f65272137de74ed18605e49257356c refs/tags/v0.1.6
771a930dc0ba86769d6862bc4dc100acc50170fa refs/tags/v0.1.6^{}
a72251d945353a360087eb78ee75287c38a1c0e6 refs/tags/v0.1.7
d69e66d7c915b9682618b7f304b80cc0ae4c7809 refs/tags/v0.1.7^{}
To confirm this, you can use git show
command to give you more details about the git object.
要确认这一点,您可以使用git show
命令为您提供有关 git 对象的更多详细信息。
This is the information from one of my test git repositories.
这是来自我的一个测试 git 存储库的信息。
$ git show 43f9a98886ba873c0468c608f24c408b9991414f
tag v0.1
Tagger: Ash <tuxdude@OptimusPrime>
Date: Sun Jul 15 00:14:43 2012 -0700
Tagging Stable repo 0.1 :)
-----BEGIN PGP SIGNATURE-----
<PGP-SIGNATURE>
-----END PGP SIGNATURE-----
commit e55df25f2321a6b2c9a02fa80ccba7cbe3c38c08
Merge: 796efcd 58e3a4d
Author: Ash <tuxdude@OptimusPrime>
Date: Sun Jul 15 00:02:44 2012 -0700
Merge branch 'dev' into 'master' for stable 0.1.
$ git show e55df25f2321a6b2c9a02fa80ccba7cbe3c38c08
commit e55df25f2321a6b2c9a02fa80ccba7cbe3c38c08
Merge: 796efcd 58e3a4d
Author: Ash <tuxdude@OptimusPrime>
Date: Sun Jul 15 00:02:44 2012 -0700
Merge branch 'dev' into 'master' for stable 0.1.