【问题标题】:GitPython: remove multiple tags locally and remoteGitPython:在本地和远程删除多个标签
【发布时间】:2020-02-18 07:26:57
【问题描述】:

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

工作非常缓慢。删除遥控器中的每个标签需要几秒钟。我有 200 多个标签,这对我来说非常耗时。

这是否可以通过一键删除所有选定的标签(tags)?

【问题讨论】:

  • 接受git push的服务器一次接受多个refspecs。我不知道如何,甚至是否可以在 GitPython 中指定。

标签: python git git-tag gitpython


【解决方案1】:

正如 torek 所说,git 本身允许在一个推送命令中使用多个 refspec。

然后 GitPython 3.0 API 参考明确提到了多个 refspecs 的可能性 (here)

(来自“Push”部分本身为该参数引用的“Fetch”部分)

Fetch 支持多个 refspecs(就像底层的 git-fetch 所做的那样)——为“refspec”提供一个列表而不是一个字符串将利用这个工具。

【讨论】:

  • remote.push(refspec=[':%s' % tag for tag in tags])
  • @phd 感谢您提供的具体语法,我不确定。
猜你喜欢
  • 2018-09-29
  • 2013-05-20
  • 2010-12-22
  • 2018-01-30
  • 2011-07-25
  • 2011-07-26
  • 1970-01-01
  • 1970-01-01
  • 2016-07-08
相关资源
最近更新 更多