英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论