标记远程 git 存储库而不克隆它
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6922700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tag a remote git repository without cloning it
提问by gfxmonk
Is there a way to tag a remote git repository without having cloned itlocally?
有没有办法标记远程 git 存储库而无需在本地克隆它?
In order to correlate a code repository with a config repository, I want to (as a CI build step) tag whatever is the current head of the config repository with build-n (where N is the current build number provided by jenkins).
为了将代码存储库与配置存储库相关联,我想(作为 CI 构建步骤)使用 build-n 标记配置存储库的当前头部(其中 N 是 jenkins 提供的当前构建号)。
The config repository isn't used as part of the build, I simply want an easy way to fetch the config revision as it was when for example version 1234 was built, and tagging it as "build-1234" seems like the simplest way to achieve this.
配置存储库不用作构建的一部分,我只是想要一种简单的方法来获取配置修订版,就像构建版本 1234 时一样,将其标记为“build-1234”似乎是最简单的方法实现这一点。
采纳答案by Legolas
To have this as an answer: there is at the moment no way to do remote tagging with git, but if you have access in some way to the remote (bare) repository, you may be able to tag on the remote location.
将此作为答案:目前无法使用 git 进行远程标记,但如果您可以某种方式访问远程(裸)存储库,则可以在远程位置进行标记。
For example, if you access the git repository via SSH, you can login using SSH, go to the (bare) repository and execute the tag command (git tag build-1234 master
) in the (bare) repository.
比如通过SSH访问git仓库,可以使用SSH登录,进入(裸)仓库,在(裸)仓库执行tag命令(git tag build-1234 master
)。
(I am not completely sure about the tool mentioned by @ruslan-kabalin)
(我不完全确定@ruslan-kabalin 提到的工具)
回答by Evan Krall
It's possible to tag the current commit at the tip of a branch remotely, but not (as far as I can tell) with git porcelain or plumbing. We'll have to speak to a remote git receive-pack
directly.
可以远程标记分支尖端的当前提交,但不能(据我所知)使用 git 瓷器或管道。我们必须git receive-pack
直接与遥控器通话。
Here's some python that uses dulwichto do what we want:
这是一些使用dulwich来做我们想做的事情的python :
#!/usr/bin/env python
from dulwich.client import get_transport_and_path
import sys
def tag_remote_branch(repo_url, branch, tag):
client, path = get_transport_and_path(repo_url)
def determine_wants(refs):
tag_ref_name = 'refs/tags/%s' % tag
branch_ref_name = 'refs/heads/%s' % branch
# try not to overwrite an existing tag
if tag_ref_name in refs:
assert refs[tag_ref_name] == refs[branch_ref_name]
refs[tag_ref_name] = refs[branch_ref_name]
return refs
# We know the other end already has the object referred to by our tag, so
# our pack should contain nothing.
def generate_pack_contents(have, want):
return []
client.send_pack(path, determine_wants, generate_pack_contents)
if __name__ == '__main__':
repo_url, branch, tag = sys.argv[1:]
tag_remote_branch(repo_url, branch, tag)
回答by Pramod Setlur
Gitlab has an API for it. Pretty confident other might have an endpoint for this. http://docs.gitlab.com/ce/api/tags.html
Gitlab 有一个 API。非常有信心的其他人可能对此有一个端点。 http://docs.gitlab.com/ce/api/tags.html