git匹配带有多个单词的标签 [英] git match tag with multiple words
问题描述
我们可以获得最后一个git标签,该标签以一个单词(例如TEST)开头,如下所示:
We can get the last git tag, which starts by a word(e.g TEST) as follow:
git describe --tag --dirty --match 'TEST*'
我想知道如何获取以word1 或 word2(例如TEST OR RUN)开头的最后一个标签?我尝试使用正则表达式或以下命令,但它不起作用:
I am wondering how can I get the last tag, which starts by word1 or word2 (e.g. TEST OR RUN)? I've tried to use regex or following but it does not work:
git describe --tag --dirty --match'TEST * | RUN *'
git describe --tag --dirty --match 'TEST*|RUN*'
解决方案:我们可以获得对HEAD的提交次数,并比较这些数字,提交次数较少的是最近的一次.您可以在我添加的答案中找到其脚本.
SOLUTION: We can get number of commits to HEAD and compare those numbers, the one which has less commits is the more recently. You can find its script in the answer, which I have added.
推荐答案
我们可以获取对HEAD的提交次数并进行比较,其中提交次数较少的是最近的一次,如下所示:
We can get number of commits to HEAD and compare those numbers, the one which has less commits is the more recently, as follow:
#!/bin/bash
V_TEST=$(git describe --tag --dirty --match 'TEST*' | awk 'BEGIN { FS = "-" }; {print $2}')
V_RUN=$(git describe --tag --dirty --match 'RUN*' | awk 'BEGIN { FS = "-" }; {print $2}')
if [[ $V_TEST -gt $V_RUN ]] ; then
VERSION=$(git describe --tag --dirty --match 'RUN*')
echo $VERSION
else
VERSION=$(git describe --tag --dirty --match 'TEST*')
fi
echo $VERSION
这篇关于git匹配带有多个单词的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!