我想从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.
...
假设我有很多标签,我想全部删除它们。
我想从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.
...
假设我有很多标签,我想全部删除它们。
当前回答
要删除远程标记(在删除本地标记之前),只需执行以下操作:
git tag -l | xargs -n 1 git push --delete origin
然后删除本地副本:
git tag | xargs git tag -d
其他回答
斯特凡的答案是不知道如何从远程删除标签。对于windows powershell,可以先删除远程标记,然后删除本地标记。
git tag | foreach-object -process { git push origin --delete $_ }
git tag | foreach-object -process { git tag -d $_ }
因为所有这些选项都只在linux中工作,下面是windows中必须处理这些问题的等效选项:
FOR /F usebackq %t IN (`git tag`) DO @git tag --delete %t
要删除所有本地标签,只需运行以下命令
git tag | xargs git tag -d
如果在执行上述命令删除本地标签后,还需要删除远端标签,可以执行以下命令
git ls-remote --tags --refs origin | cut -f2 | xargs git push origin --delete
注意:用远程处理程序替换原点
如果你的本地回购中没有这些标签,你可以删除远程标签,而不必把它带到本地回购。
git ls-remote --tags --refs origin | cut -f2 | xargs git push origin --delete
不要忘记将“origin”替换为远程处理程序名称。
windows用户:
这将通过运行git tag并将该列表提供给git tag -d来删除所有本地标签:
FOR /f "tokens=*" %a in ('git tag') DO git tag -d %a
(网址:https://gist.github.com/RandomArray/fdaa427878952d9768b0)