我想从Git存储库中删除所有标记。我该怎么做呢?

使用git tag -d tagname在本地删除标签tagname,并使用git push——tags更新git provider上的标签。

我试着:

git tag -d *

但是我看到*表示当前目录中的文件。

$ git tag -d *
error: tag 'file1' not found.
error: tag 'file2' not found.
...

假设我有很多标签,我想全部删除它们。


当前回答

使用通配符模式删除本地和远程标记的一行代码。

TAGPATTERN = " 0.1。*”;——删除$(git标签-l $TAGPATTERN);git标签-d $(git标签-l $TAGPATTERN)

远程标记首先被删除,因为列表是从本地生成的。

其他回答

斯特凡的答案是不知道如何从远程删除标签。对于windows powershell,可以先删除远程标记,然后删除本地标记。

git tag | foreach-object -process { git push origin --delete $_ }
git tag | foreach-object -process { git tag -d $_ }  

我必须删除带有前缀的标签

例如,我必须删除标签v0.0.1, v0.0.2, v0.0.3, v0.0.4, v0.0.5

git tag -d $(git tag -l "v0.0.*")

分解并解释上面的语句:

列出所有带有前缀的标签 Git标签-l "v0.0.*" 删除标签 Git标记-d $tag_names

这就是这个表述的原理

windows用户:

这将通过运行git tag并将该列表提供给git tag -d来删除所有本地标签:

FOR /f "tokens=*" %a in ('git tag') DO git tag -d %a

(网址:https://gist.github.com/RandomArray/fdaa427878952d9768b0)

对于windows,这样做是为了删除远程标记:

git fetch --tags
git push origin --delete $(git tag -l)

显示所有包含"v"的标签

git tag -l | grep v | xargs -n 1 sh -c 'echo "Processing tag $0\n" && git show -s $0'