python - GitPython:本地和远程删除多个标签

标签 python git git-tag gitpython

我正在使用 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/

相关文章:

python - 如何提取图像的边界(OCT/视网膜扫描图像)

python - functools.wraps 相当于类装饰器

python - django RuntimeError at/admin/users/user/1/change/, 单线程执行器已经被使用,会死锁

python - pandas ExcelWriter 从右到左写入工作表

git - 如何每次都将未知名称的分支推送到远程?

git - 无法登录 SourceTree

c++ - 如何克隆外部(来自 git)cmake 项目并将其集成到本地项目中

git - Monorepo 版本标签约定

git - 是否每个git标记都有关联的提交ID?

git - git标签可以重用吗