从 git 仓库中找出标签

Grep out tags from git repo

正在尝试使用 shell 从我的仓库中找出不同的标签:

git ls-remote --tags git@mit.usa.com:s1836/pro-ti.git | awk '{print }'

Returns,我怎样才能只找出不同的标签,如 v1、v2、v3、v4:

refs/tags/v1
refs/tags/v1^{}
refs/tags/v2
refs/tags/v2^{}
refs/tags/v3
refs/tags/v3^{}
refs/tags/v4
refs/tags/v4^{}

您可以通过管道将上述 git 命令传送到此 awk:

git ls-remote --tags git@mit.usa.com:s1836/pro-ti.git | awk '
    {split(,a,"[/^{]"); s[a[3]]} END{for (i in s) print i}'
v1
v2
v3
v4

grepuniq 怎么样:

... | grep -o 'v[0-9]\+' | sort | uniq

使用 GNU awk 进行多字符 RS:

$ gawk -v RS='(\^\{\})?\n' -F'/' '!seen[$NF]++{print $NF}' file
v1
v2
v3
v4