How to get list of latest tags in remote git?

后端 未结 4 1323
余生分开走
余生分开走 2020-12-24 06:05

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.

I know about \"git ls-remot

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-24 06:15

    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 '[^\/]*$'
    

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

    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
    

    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'.

    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).

提交回复
热议问题