[英]Find branch of a tag on remote git repository
I'm trying to automate buildsteps with a gui and want to create a json-file with all available tags and branch-heads for selection.我正在尝试使用 gui 自动化构建步骤,并希望创建一个包含所有可用标签和分支头的 json 文件以供选择。 I can already list all branches and tags in a repository by using
我已经可以通过使用列出存储库中的所有分支和标签
git ls-remote --tags/heads url-of-repo
Now I want to know, which tag belongs to a branch.现在我想知道,哪个标签属于一个分支。 I could do something like
我可以做类似的事情
git branch --contains tags/<tag>
But I want to avoid checking out all repositories locally to just get this information.但我想避免在本地检查所有存储库以获取此信息。 Maybe there's a command to directly show all tags of a branch?
也许有一个命令可以直接显示一个分支的所有标签?
Make a clone, a bare one,做一个克隆,一个光秃秃的,
git clone --bare url-of-repo
Every time you want to list the branches, update the branches and tags first,每次要列出分支时,先更新分支和标签,
cd path-to-the-bare-repo
git fetch origin +refs/heads/*:refs/heads/* +refs/tags/*:refs/tags/*
and then run然后运行
git branch --contains tags/<tag>
I'd recommend git for-each-ref , which allows to format the output and is more script-friendly.我推荐git for-each-ref ,它允许格式化 output 并且对脚本更友好。 For example,
例如,
git for-each-ref refs/heads --contains tags/<tag> --format="%(refname:lstrip=2)"
If you don't want to use cd
in the script, you could also export GIT_DIR
and unset it.如果您不想在脚本中使用
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
or simply或者干脆
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)"
If you don't want to make a local clone, and you have access to the hosting server.如果您不想进行本地克隆,并且您可以访问托管服务器。 Another option is to run a web service to query the branches in the repository hosted in the server.
另一种选择是运行 web 服务来查询服务器中托管的存储库中的分支。 You could use
django
to write and run such a service in several minutes.您可以使用
django
在几分钟内编写和运行这样的服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.