git tag 与branch 不同,tag是用于为指定的commit添加共享信息的。因此当你辛辛苦苦的为本地仓库清理完了tag列表后,同事又推送了之前的本地tag,心情可想而知。
为什么同事会将本地tag全部推送上来呢?
- 可能性1:
git push --tags,有可能你的小伙伴在本地仓库创建了多个tag,在提交代码时期望对这些tag全部进行更新,于是使用了git push --tags,顺手将你清理的tag又全部推送回来了。 - 可能性2:设置了
push = +refs/tags/*:refs/tags/*,有可能你的小伙伴在git设置中对git push同时,对所有的tag进行推送。
那么这个问题怎么解决呢?
- 堆栈网有小伙伴表示在git1.7.8-1.8.5.6版本期间,直接使用
git fetch <remote> --prune --tags可以将本地tags与远端tags进行同步,并清理本地的无用tags。但是这个方法在git1.9.0之后已经失效了 - 而对于新版本的git,推荐使用
git fetch --prune <remote> "+refs/tags/*:refs/tags/*",在fetch的同时,更新远端的tag列表。 - 另外,一劳永逸的方法是在git设置
git fetch= +refs/tags/*:refs/tags/*, 命令行中写法为git config --local --add remote.origin.fetch "+refs/tags/*:refs/tags/*",之后每次``git fetch --prune`,都会更新tag列表
参考链接: git tag - Do git tags get pushed as well? - Stack Overflowgit tag - Remove local git tags that are no longer on the remote repository - Stack Overflowhttps://stackoverflow.com/questions/41843266/microsoft-windows-python-3-6-pycrypto-installation-error)
Does "git fetch --tags" include "git fetch"? - Stack Overflow