git 中批量删除标签TAG的方法

git 中批量删除标签TAG的方法

注意:有些版本的ubuntu 中/bin/sh指向的是dash 而不是bash, 建议用 bash xxx.sh <正则表达式> 的方式执行

#!/bin/bash
# 管理员按一定的条件删除过期的标签

cd /_git/master/xxxx
## 删除当前以及子模块中的标签
deleteTag() {
    echo "delete tag $1"
    git tag -d $1
    git push origin :refs/tags/$1
    git submodule foreach git tag -d $1
    git submodule foreach git push origin :refs/tags/$1
}


for tagName in `git tag`
do
        if `echo $tagName|grep $1` == 0; then
            echo "delete tag:$tagName"
            deleteTag $tagName
        fi
        # 可以用于判断删除条件 if [ ${#tagName} -gt 17 ]  && [ ${tagName:0:17} == "x.00.10.x2x10-20_" ]; then
        #    deleteTag $tagName
       # fi
done

删除标签后,各客户端可以通过以下方法同步

#先删除
git tag -l | xargs git tag -d
# 再更新
git fetch --tags

猜你喜欢

转载自blog.csdn.net/looyo/article/details/80365580