简体   繁体   中英

List all tags from all branches younger than the latest tag on master

For automation purposes I need to find all tags from all branches which are younger than the latest tag on master.

My code is unfortunately returning me as well one tag which is one before the latest

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

On master I have tags
R.01.02.03
R.01.01.01

on feature branches I have tags (they are younger than tags on master)
B.02.01.01
B.02.01.02
B.02.01.03
B.02.01.04

I get a list:
B.02.01.01
B.02.01.02
B.02.01.03
B.02.01.04
R.01.02.03
R.01.01.01

I need a list:
B.02.01.01
B.02.01.02
B.02.01.03
B.02.01.04

# 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM