How to REALLY remove a tag on git / SourceTree

試著忘記壹切 提交于 2019-12-10 13:41:29

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/35334141/how-to-really-remove-a-tag-on-git-sourcetree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!