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

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


当前回答

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

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

其他回答

你还可以使用:

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'

对于使用PowerShell的Windows用户:

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

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

要删除远程标记(在删除本地标记之前),只需执行以下操作:

git tag -l | xargs -n 1 git push --delete origin

然后删除本地副本:

git tag | xargs git tag -d

在本地,git标记只是磁盘上存储在.git/refs/tags子文件夹中的文件。

你可以只cd .git/refs/tags并删除存储在那里的所有文件,使用你最喜欢的删除文件的方法(rm *,从文件资源管理器UI删除等)。