无需克隆即可从远程回购获取最后的git标签 [英] Get last git tag from a remote repo without cloning
问题描述
在我的本地副本中,我使用 describe $> c $ c $
$ g $ git describe --abbrev = 0 --tags
但是我不能在远程存储中使用 describe >
使用 git ls-remote --tags< repository>
例如,if我们想知道Git在我们的最新标签会做什么
git ls-remote --tags git:// github.com/git/git.git
返回一个长列表,所有标签按字母顺序排列,如下所示(为了理性,截断)。
最后一行告诉我们最新的标签是 v1.8.0-rc0
。
记住该标签可以是任何类型的字符串,正如 Christopher Gervais 在他的回答, git ls-remote
按字母顺序排列标签 。不幸的是 git ls-remote
没有 - sort
选项(例如 git for-each-ref
),所以你最好的选择是使用原生 sort
。
更新版本的 sort
支持 -V
或 - version-sort
标志来做一个自然的(版本)号码在文本中。
所以要对它们进行排序自然地,你的命令将如下所示:
git ls-remote --tags git:// github。 com / git / git.git | sort -t'/'-k 3 -V
请查看(和upvote)< a href =https://stackoverflow.com/questions/10649814/#19274639> Christopher Gervais的答案如果您需要更多/其他 grep
ing选项。
...
e4dc716b1cfefb0e1bd46c699d4f74009118d001 refs / tags / v1。 7.9
828ea97de486c1693d6e4f2c7347acb50235a85d refs / tags / v1.7.9 ^ {}
cc34c0417dfd4e647e41f3d34a032b7164aadea7 refs / tags / v1.7.9-rc0
eac2d83247ea0a265d923518c26873bb12c33778 refs / tags / v1.7.9-rc0 ^ {}
ad2ec9a47a031ebf056444a94bea3750aaa68f63裁判/标签/ v1.7.9-RC1
6db5c6e43dccb380ca6e9947777985eb11248c31裁判/标签/ v1.7.9-RC1 ^ {}
eab05abaeb51531e11835aaa4c26564a1babebac裁判/标签/ v1.7.9-RC2
bddcefc6380bd6629f3f12b5ffd856ec436c6abd裁判/标签/v1.7.9-rc2^ {}
...
5ace0b7af106b44687005085d8c252f8be9da5d3 refs / tags / v1.8.0-rc0
b0ec16b49eb283156e13bbef26466d948e4fd992 refs / tags / v1.8.0-rc0 ^ {}
How to get last tag from a (non checked-out) remote repo?
On my local copy I use describe
git describe --abbrev=0 --tags
But I cannot use describe
with remote storage
Use git ls-remote --tags <repository>
For example, if we want to know what the latest tag that Git is at we would do
git ls-remote --tags git://github.com/git/git.git
That returns a long list with all the tags in alphabetical order, as shown below (truncated for sanity's sake).
The last line tells us the latest tag is v1.8.0-rc0
.
Keep in mind that tags can be any kind of string so, as pointed out by Christopher Gervais in his answer, git ls-remote
sorts tags alphabetically. Unfortunately git ls-remote
does not have a --sort
option (like, for example git for-each-ref
), so your best option is to use native sort
.
More recent versions of sort
support the -V
or --version-sort
flag to do a natural sort of (version) numbers within text.
So to sort them naturally, your command would look like this:
git ls-remote --tags git://github.com/git/git.git | sort -t '/' -k 3 -V
Please take a look at (and upvote) Christopher Gervais's answer below if you need more/other grep
ing options.
...
e4dc716b1cfefb0e1bd46c699d4f74009118d001 refs/tags/v1.7.9
828ea97de486c1693d6e4f2c7347acb50235a85d refs/tags/v1.7.9^{}
cc34c0417dfd4e647e41f3d34a032b7164aadea7 refs/tags/v1.7.9-rc0
eac2d83247ea0a265d923518c26873bb12c33778 refs/tags/v1.7.9-rc0^{}
ad2ec9a47a031ebf056444a94bea3750aaa68f63 refs/tags/v1.7.9-rc1
6db5c6e43dccb380ca6e9947777985eb11248c31 refs/tags/v1.7.9-rc1^{}
eab05abaeb51531e11835aaa4c26564a1babebac refs/tags/v1.7.9-rc2
bddcefc6380bd6629f3f12b5ffd856ec436c6abd refs/tags/v1.7.9-rc2^{}
...
5ace0b7af106b44687005085d8c252f8be9da5d3 refs/tags/v1.8.0-rc0
b0ec16b49eb283156e13bbef26466d948e4fd992 refs/tags/v1.8.0-rc0^{}
这篇关于无需克隆即可从远程回购获取最后的git标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!