[英]GitPython Clone repository error
我想用參數( --recursive
, -b <branch>
)克隆git存儲庫,但是出現以下錯誤。
Traceback (most recent call last):
File "./git-clone.py", line 15, in <module>
r = git.Repo.clone(repo_dir, b=branch, recursive=git_url)
TypeError: unbound method clone() must be called with Repo instance as first argument (got str instance instead)
這是我的代碼:
#!/usr/bin/env python
import git
import os
import shutil
git_url = "<url>..."
repo_dir = "/home_local/user/git-repository"
branch = "branch"
if os.path.exists(repo_dir):
shutil.rmtree(repo_dir)
r = git.Repo.clone(repo_dir, b=branch, recursive=git_url)
如果我更換git.Repo.clone
與git.Repo.clone_from
其工作正常,但此命令不接受我的參數。
嘗試:
r = git.Repo.clone_from(git_url, repo_dir, branch=branch, recursive=True)
第一個參數是從中克隆(遠程存儲庫)的位置。 第二個參數是您要存儲克隆的位置。 所有其他參數都傳遞給git-clone
命令。 例如--branch="branch"
和--recursive
。 您可能應該堅持使用長參數名稱而不是縮寫。 由於是否存在遞歸標志,因此其值只能為True或False。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.