简体   繁体   English

在远程git存储库中查找与给定标签相同提交的所有标签

[英]Find all tags at same commit as a given tag in a remote git repository

I am trying to find all tags that are at the same commit as a given tag in a remote git repository. 我试图在远程 git存储库中查找与给定标签具有相同提交的所有标签。 If at all possible, I do not want to clone a local copy of the remote. 如果有可能,我不想克隆远程的本地副本。

For example, I have a repository where the two tags release/latest and release/1.00 both point to the same commit. 例如,我有一个存储库,其中两个标记release/latestrelease/1.00都指向同一提交。 So, given the tag release/latest I want my script to return release/1.00 . 因此,给定标签release/latest我希望我的脚本返回release/1.00

I am using ls-remote to list the remote tags: 我正在使用ls-remote列出远程标签:

git ls-remote --tags gitolite@myserver.example.org:/base.git

This command returns 该命令返回

ad759      refs/tags/release/1.00
0e9d0      refs/tags/release/1.00^{}
de388      refs/tags/release/latest
0e9d0      refs/tags/release/latest^{}

(I shortened the commit hashes to save space.) (我缩短了提交哈希以节省空间。)

I do not know how to interpret this: Why are there two lines for each tag? 我不知道如何解释:为什么每个标签有两行? Which reference points to the "real" tags? 哪些参考文献指向“真实”标签? Should I ignore the tags not followed by ^{} ? 我应该忽略不带^{}的标记吗?

The tags ending with ^{} are the actual ( lightweight ) tags to git commits; ^{}结尾的标签是git commit的实际( 轻量级 )标签; whereas the ones without this suffix are (PGP-)signed or otherwise annotated ones. 而没有此后缀的是(PGP-)签名或其他注释的。

On a remote repository, you'll have to parse the output of ls-remote , like this: 在远程存储库上,您必须解析ls-remote的输出,如下所示:

tags=$(git ls-remote --tags gitolite@myserver.example.org:/base.git)
REV=$(echo "$tags" | sed -n 's#\s*refs/tags/release/latest$##p')
echo "$tags" | sed -n "s#$REV\s*refs/tags/##p"

On a local (1.7.0) repository, you could simply use 在本地(1.7.0)存储库中,您可以简单地使用

git tag --points-at release/latest

On pre-1.7.0, substitute ls-remote with git show-ref --tags -d in the remote solution. 在1.7.0之前的版本中,在远程解决方案中用git show-ref --tags -d替换ls-remote。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM