Skip to main content
 首页 » 编程设计

python之gitpython中clone_from中的非值参数

2025年02月15日7jillzhang

我正在尝试使用 gitpython 库中的 clone_from 函数,我想传递 git clone 参数 --no-checkout 命令。

根据文档,参数必须作为 **kwargs 传递,据我所知,这必须是一个字典,其中键是 git 参数,值对应于参数值。我的问题是 --no-checkout 不接受任何参数值。

我试过类似的东西:

clone_kwargs = {'no-checkout'} 
repo.clone_from(clone_url,local_repo_path,None,None,**clone_kwargs)'' 

和

clone_kwargs = {'no-checkout':''} 
repo.clone_from(clone_url,local_repo_path,None,None,**clone_kwargs) 

和

clone_kwargs = {'':'no-checkout'} 
repo.clone_from(clone_url,local_repo_path,None,None,**clone_kwargs) 

但是所有这些尝试都失败了。那么,如何在不检查的情况下最好地克隆存储库?

请您参考如下方法:

This issue在 gitpython 项目中解释了你需要做什么:

Repo.clone_from(url, to, no_checkout=True) 

所以在你的情况下会是:

repo.clone_from(clone_url, local_repo_path, no_checkout=True)