git - 在远程 git 存储库上查找标签的分支
问题描述
我正在尝试使用 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,它允许格式化输出并且对脚本更友好。例如,
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
在几分钟内编写和运行这样的服务。
推荐阅读
- angular - 重新加载路由器链接onclick
- swift - 斯威夫特4。字典合并
- silverstripe - Silverstripe - 如何创建页面作为部署的一部分?
- java - CRUD 存储库不能在“简单”java 类中工作
- postgresql - 获取 Postgresql 中每个月的最后一个值
- html - CSS 中的定位:将子 DIV 中的文本居中对齐,该子 DIV 已在父 DIV 中水平和垂直对齐
- python - 从子子文件夹导入模块的问题
- php - 通过联系表格在 YII2 中发送电子邮件 发送到另一个地址
- c# - 如何调整数据网格列
- angular - 确认失败:第一个参数“验证码”必须是有效字符串