[英]Find branch of a tag on remote git repository
我正在尝试使用 gui 自动化构建步骤,并希望创建一个包含所有可用标签和分支头的 json 文件以供选择。 我已经可以通过使用列出存储库中的所有分支和标签
git ls-remote --tags/heads url-of-repo
现在我想知道,哪个标签属于一个分支。 我可以做类似的事情
git branch --contains tags/<tag>
但我想避免在本地检查所有存储库以获取此信息。 也许有一个命令可以直接显示一个分支的所有标签?
做一个克隆,一个光秃秃的,
git clone --bare url-of-repo
每次要列出分支时,先更新分支和标签,
cd path-to-the-bare-repo
git fetch origin +refs/heads/*:refs/heads/* +refs/tags/*:refs/tags/*
然后运行
git branch --contains tags/<tag>
我推荐git for-each-ref ,它允许格式化 output 并且对脚本更友好。 例如,
git for-each-ref refs/heads --contains tags/<tag> --format="%(refname:lstrip=2)"
如果您不想在脚本中使用cd
,您也可以导出GIT_DIR
并取消设置。
export GIT_DIR=path-to-the-bare-repo
git fetch origin +refs/heads/*:refs/heads/* +refs/tags/*:refs/tags/*
git for-each-ref refs/heads --contains tags/<tag> --format="%(refname:lstrip=2)"
unset GIT_DIR
或者干脆
GIT_DIR=path-to-the-bare-repo git fetch origin +refs/heads/*:refs/heads/* +refs/tags/*:refs/tags/*
GIT_DIR=path-to-the-bare-repo git for-each-ref refs/heads --contains tags/<tag> --format="%(refname:lstrip=2)"
如果您不想进行本地克隆,并且您可以访问托管服务器。 另一种选择是运行 web 服务来查询服务器中托管的存储库中的分支。 您可以使用django
在几分钟内编写和运行这样的服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.