本文介绍了仅获取git远程存储库的标签/引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在不下载对象/文件的情况下获取存储库(例如GitHub)的标签/引用?
Is it possible to get the tags / references of a repository (eg GitHub) without downloading objects / files?
我的用例是包装某些软件的最新Beta版本,这些软件具有悠久的历史,因此很容易克隆.
My use case is in packaging the latest beta release of some software which has a long history and is therefore large to clone.
理想的是,在确定要使用的标签之后,我可以:
Ideally after I determine the tag that I wish to use, I can then:
git clone -b "$tag" --depth=1
推荐答案
使用 git ls-remote
:
$ git ls-remote -t --refs <URL>
这将给出如下输出:
8f235769a2853c415f811b19cd5effc47cc89433 refs/tags/continuous
24e666ed73486a2ac65f09a1479e91e6ae4a1bbe refs/tags/continuous-develop
7c2cff2c26c1c2ad4b4023a975cd2365751ec97d refs/tags/v2.0
35b69eed46e5b163927c78497983355ff6a5dc6b refs/tags/v2.0-beta10
您可能还希望通过--exit-code
,以确保在没有匹配的引用返回时非0
退出.
You probably also want to pass --exit-code
to ensure a non-0
exit when no matching refs are returned.
要仅获取标签名称,请传递:
To get only the tag names, pass through:
sed -E 's/^[[:xdigit:]]+[[:space:]]+refs\/tags\/(.+)/\1/g'
:
$ git ls-remote -t --exit-code --refs https://github.com/robert7/nixnote2.git \
| sed -E 's/^[[:xdigit:]]+[[:space:]]+refs\/tags\/(.+)/\1/g'
continuous
continuous-develop
v2.0
v2.0-beta10
建议:
- 传递
--exit-code
以确保在没有匹配的引用返回时退出非0
的情况. - 使用
https://
版本:速度更快,并且如果您要打包,则不想冒被要求输入ssh密钥的风险. -
--sort=-v:refname
按版本而不是按字母顺序排序,并且顶部具有最大的版本 - 使用
git -c versionsort.suffix=-
防止2.0-rc
在"2.0
之后" - 在命令行末尾添加一个模式以进行过滤.例如,如果所有版本标签均以
v
开头,则为'v*'
.
- Pass
--exit-code
to ensure a non-0
exit when no matching refs are returned. - Use the
https://
version: it's faster and if you're packaging you don't want to run the risk of being asked for a ssh key. --sort=-v:refname
to sort by version rather than lexographically, and have the largest versions at the top- Use
git -c versionsort.suffix=-
to prevent2.0-rc
coming "after"2.0
- Add a pattern at the end of the command line to filter. Eg
'v*'
if all version tags start with av
.
这篇关于仅获取git远程存储库的标签/引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!