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