如何获得远程git中最新标签的列表? [英] How to get list of latest tags in remote git?

查看:120
本文介绍了如何获得远程git中最新标签的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多方法可以在您拥有本地git回购时获取最新的代码。

There are alot of methods to get latest tags when you have local git repo.

但我想要获得远程回购的最新代码列表。

But i want to get list of latest tags on remote repo.

我知道git ls-remote,当你使用像x.y.z这样的标签(其中x,y,z是数字)时,一切都很好。
但是当标签看起来像test-x.y.z和dev-x.y.z时,我注意到大量的测试标签会将任何新的dev标签取出,这是不正确的。

I know about "git ls-remote", and everything is fine when you use tags like x.y.z (where x,y,z are numbers). But when tags looks like "test-x.y.z" and "dev-x.y.z" i noticed that large amount of "test" tags will pull out any new "dev" tags, which is not correct.

那么,您想如何解决这个问题?

So, how would you like solve this?

推荐答案

你用linux?如果是这样你可以使用这个命令

Do you use linux? If so you can use this command

git ls-remote --tags | grep -o 'refs/tags/dev-[0-9]*\.[0-9]*\.[0-9]*' | sort -r | head | grep -o '[^\/]*$'

它会显示10个最新的标签(名称 dev-xyz

It will show you 10 latest tags (with name dev-x.y.z)

UPD

您可以使用此bash脚本获取最新的标签:

UPD
You can use this bash script to get latest tags:

#!/bin/bash

TAGS=("dev-[0-9]*\.[0-9]*\.[0-9]*" "test-[0-9]*\.[0-9]*\.[0-9]*" "good-[0-9]*" "new [0-9][0-9][0-9]")

for index in ${!TAGS[*]}
do
    git ls-remote --tags | grep -o "refs/tags/${TAGS[$index]}" | sort -rV | head | grep -o '[^\/]*$'
done

数组标签正则表达式,你会得到10个最新的标签为他们每个人。如果您想获得更多或更少的标签,只需将param -n添加到头部命令'head -n 5'或'head -n 15'。

Just add in array TAGS regular expressions that you want, and you'll get 10 latest tags for every of them. If you want to get more or less tags, just add param -n to head command 'head -n 5' or 'head -n 15'.

以防万一。将它保存到文件夹〜/ bin中(例如使用名称git_tags),然后添加可执行权限(chmod + x git_tags),这将允许您从每个位置运行此bash脚本(只需键入git_tags)。

Just in case. Save it in folder ~/bin (for example with name git_tags), then add executable permission (chmod +x git_tags), this will allow you to run this bash script from every place (just type git_tags).

这篇关于如何获得远程git中最新标签的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆