【问题标题】:Cloning only the main branch using PyGit2使用 PyGit2 仅克隆主分支
【发布时间】:2016-04-15 04:07:42
【问题描述】:

我想克隆一些远程存储库,但只检索主分支。

我的代码目前获得了所有的分支。

def init_remote(repo, name, url):
    # Create the remote with a mirroring url
    remote = repo.remotes.create(name, url, "+refs/*:refs/*")
    # And set the configuration option to true for the push command
    mirror_var = "remote.{}.mirror".format(name)
    repo.config[mirror_var] = True
    # Return the remote, which pygit2 will use to perform the clone
    return remote

pygit2.clone_repository(url, "../../clones/"+location, remote=init_remote)

【问题讨论】:

    标签: python git libgit2 pygit2


    【解决方案1】:

    您的代码不仅获取所有分支,它还镜像远程,同时获取 远程跟踪分支,这可能会导致一些混乱的布局。

    您已经在设置自己的 refspec,所以您需要做的是设置 refspec 以下载默认分支。如果您知道,您可以更改代码以获得一个分支

    remote = repo.remotes.create(name, url, "+refs/heads/master:refs/heads/master")
    

    【讨论】:

      猜你喜欢
      • 2021-07-11
      • 2022-01-20
      • 1970-01-01
      • 2021-06-26
      • 2010-12-25
      • 2017-05-05
      • 2011-05-15
      • 2013-02-24
      • 2017-03-30
      相关资源
      最近更新 更多