列出所有分支的所有标签,这些分支比master上的最新标签小

时间:2019-02-14 07:20:20

标签: bash git git-bash

出于自动化目的,我需要从所有分支中查找所有标签,这些分支比master上的最新标签还年轻。

很遗憾,我的代码还给我返回了一个标签,该标签比最新的标签早了

git describe  --abbrev=0 --tags $(git rev-list --tags --date-order --since="$(git log -1 --format=%at $(git describe --abbrev=0 --tags))") | sort -u

在主菜单上,我有标签
R.01.02.03
R.01.01.01

在功能分支上,我有标签(它们比主标签上的标签年轻)
B.02.01.01
B.02.01.02
B.02.01.03
B.02.01.04

我得到一个列表:
B.02.01.01
B.02.01.02
B.02.01.03
B.02.01.04
R.01.02.03
R.01.01.01

我需要一个列表:
B.02.01.01
B.02.01.02
B.02.01.03
B.02.01.04

1 个答案:

答案 0 :(得分:0)

# Get the last tag on master
LAST_MASTER_TAG=`git describe --tags --abbrev=0 master`

# Get its taggerdate in Unix timestamp format
LMT_UNIX_DT=`git for-each-ref --format '%(taggerdate:unix)' refs/tags/$LAST_MASTER_TAG`

# List all tags in the format `refname unix_timestamp`
# and filter the list by those timestamps
# that are greater then LMT_UNIX_DT
git for-each-ref --sort=taggerdate --format='%(refname) %(taggerdate:unix)' refs/tags/ |
while read refname dt; do
    if test $dt -gt $LMT_UNIX_DT; then
        echo $refname;
    fi;
done