如何真正删除git / SourceTree上的标签 [英] How to REALLY remove a tag on git / SourceTree

查看:1328
本文介绍了如何真正删除git / SourceTree上的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何从SourceTree中删除一个标签。只需右键单击,删除,然后勾选从所有遥控器上删除标签。然后执行以下操作(为了便于阅读,我忽略了标记 -c diff.mnemonicprefix = false -c core.quotepath = false ):

  git tag -d my_tag 
git push -v origin:refs / tags / my_tag

这是有效的。



这是问题。



一段时间后,其他开发人员之一将推送他们的功能分支到源,SourceTree会自动将所有本地标签推送到远程服务器。这将重新创建我刚刚删除的标签。



我知道这个想法是标签不是应该被删除的,例如,标签发布,但有时会发生错误。



任何建议吗?

解决方案

我发现的唯一解决方案就是让所有其他开发人员在您从远程中删除标签后删除标签的本地副本。我发现脚本帮助这里


简单来说,如果你正在尝试做一些像git fetch -p
- t,从git版本1.9.4开始无法使用。



然而,有一个简单的解决方法仍然适用于最新的
版本:

  git tag -l | xargs git tag -d#删除所有本地标记
git fetch -t#fetch远程标记

一行可以写成:

  git tag -l | xargs git tag -d&& git fetch -t 

另外,您可以在〜/ .gitconfig文件中添加一个新的别名在〜/ .gitconfig中


$ b $ pre code别名

pt =!git tag -l | xargs git tag -d&& git fetch -t

现在,您可以简单地调用pt别名来修剪局部过时标记:

  git pt 



I know how to delete a tag from SourceTree. Just right-click, delete, and tick "remove tag from all remotes." It then executes the following (and I'm omitting the flags -c diff.mnemonicprefix=false -c core.quotepath=false for readability):

git tag -d my_tag
git push -v origin :refs/tags/my_tag

This works.

Here is the problem.

Some time later, one of the other developers will push their feature branch to origin, and SourceTree will automatically push all local tags to the remote server. This will recreate the tag I just deleted.

I know the idea is that tags are not "supposed" to be deleted, e.g. tagged releases, but sometimes mistakes happen.

Any advice?

解决方案

The only solution I have found is to simply ask all the other developers to remove their local copies of the tags after you have deleted them from the remote. I found a script help here.

To put it simple, if you are trying to do something like git fetch -p -t, it will not work starting with git version 1.9.4.

However, there is a simple workaround that still works in latest versions:

git tag -l | xargs git tag -d # remove all local tags
git fetch -t                  # fetch remote tags

A one liner can be written as:

git tag -l | xargs git tag -d && git fetch -t

Alternative, you can add a new alias to your ~/.gitconfig file to make things shorter:

in ~/.gitconfig

[alias]

     pt = !git tag -l | xargs git tag -d && git fetch -t 

Now, you can simply call pt alias to prune local stale tags:

git pt

这篇关于如何真正删除git / SourceTree上的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆