检查是否推送了带有相关提交的 Git 标签。

huangapple go评论55阅读模式
英文:

Check if a git tag is pushed with related commit

问题

I need to check automatically if a TAG has been pushed on remote, if the commits related with the commit has been pushed and if the TAG/commit is on a specific branch.

Currently I'm using git ls-remote but I can just check if tag is pushed or not. Not enough.

I tried to clone locally the repository with git clone --branch to get specific TAG, however in this way I can't have information about the branch where TAG is, if I use the command git branch the output is just

  • (no branch)

Do I need to clone the repository? How can I clone the repository without the whole history just to perform this kind of check?

英文:

I need to check automatically if a TAG has been pushed on remote, if the commits related with the commit has been pushed and if the TAG/commit is on a specific branch.

Currently I'm using git ls-remote but I can just check if tag is pushed or not. Not enough.

I tried to clone locally the repository with git clone --branch to get specific TAG, however in this way I can't have information about the branch where TAG is, if I use the command git branch the output is just

* (no branch)

Do I need to clone the repository? How can I clone the repository without the whole history just to perform this kind of check?

答案1

得分: 1

你可以尝试使用 git branch -a --contains $tagname 或者 git branch -r --contains $tagname。在你的情况下,tagname 也可以是 HEAD。但是,你仍然需要克隆整个历史记录,因为标记的提交可能可以从多个分支访问,并且没有整个历史记录,我们无法精确地找出这些分支到底是什么。如果你不想每次都克隆,你可以保留一个仓库,在检查标记是否被分支包含之前,先获取所有标记和分支。

另一种选择是在托管远程仓库的服务器上运行一个服务,比如 Django 服务。它也可以在托管与远程仓库不断同步的镜像仓库的服务器上运行。向服务发送一个请求。服务找出包含标记/提交的分支,在具有完整历史记录的托管仓库中,然后返回结果。

英文:

You could try git branch -a --contains $tagname or git branch -r --contains $tagname. tagname could also be HEAD in your case. But still, you need to clone the whole history because the tagged commit could be reachable from multiple branches, and without the whole history we cannot precisely find out what exactly these branches are. If you don't want to clone it every time, you could keep a repository and fetch all tags and branches first before checking if a tag is contained by a branch.

An alternative is to run a service, like a Django service, on the server that hosts the remote repository. It could also be on a server that hosts a mirror repository that syncs with the remote repository constantly. Send a request to the service. The service finds out the branches that contain the tag/commit in the hosted repository that has the whole history, and then returns the result.

huangapple
  • 本文由 发表于 2023年3月9日 16:57:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75682340.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定