我正在使用 GitPython 删除多个标签。我用这段代码来做到这一点:
def delete_tags(self, tags):
remote = self.__repo.remote(name='origin')
for tag in tags:
self.__repo.git.tag('-d', tag) # remove locally
remote.push(refspec=(':%s' % (tag))) # remove from remote
我的这段代码存在性能问题。命令
remote.push(refspec=(':%s' % (tag)))
运行速度非常慢。删除 Remote 中的每个标签需要几秒钟的时间。我有 200 多个标签,这消耗了我很多时间。
是否可以通过一次推送删除所有选定的标签 (tags
)?
最佳答案
正如 torek 评论的那样,git 本身允许在推送命令中使用多个引用规范。
然后 GitPython 3.0 API 引用明确提到了多个 refspec 的可能性 ( here )
(来自该参数的“Push”部分本身引用的“Fetch”部分)
Fetch supports multiple refspecs (as the underlying git-fetch does) - supplying a list rather than a string for ‘refspec’ will make use of this facility.
关于python - GitPython:本地和远程删除多个标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58499296/