我想从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.
...

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


当前回答

如果你有很多upstream (origin)标签需要删除,Powershell v7支持parallel foreach:

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

其他回答

对于使用PowerShell的Windows用户:

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

这将通过对返回的每一行执行git tag -d来删除git标签返回的所有标签。

你还可以使用:

git tag -d $(git tag)

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

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

如果你的本地回购中没有这些标签,你可以删除远程标签,而不必把它带到本地回购。

git ls-remote --tags --refs origin | cut -f2 | xargs git push origin --delete

不要忘记将“origin”替换为远程处理程序名称。

并行化和过滤了最新版本

git tag -l "v1.0.*" | xargs -L 1 | xargs git push origin --delete
git fetch origin --prune --prune-tags

第一行,并行地从remote中删除所有匹配的标记。 第二行,从git v2.26.2版本中删除所有已删除的标记,从而更新当前的repo。

为了测试您可以添加的第一行——dry-run,我还鼓励您探索标记列表命令,它有很好的通配符和排除/包含。