如何使用 GitPython 库在禁用 SSL 检查的情况下进行克隆。下面的代码...
import git
x = git.Repo.clone_from('https://xxx', '/home/xxx/lala')
Run Code Online (Sandbox Code Playgroud)
...产生此错误:
Error: fatal: unable to access 'xxx': server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none
Run Code Online (Sandbox Code Playgroud)
我知道“export GIT_SSL_NO_VERIFY=1”,但是如何在 python 库中实现它?
我正在使用 GitPython 从 Gitlab 服务器克隆存储库。
git.Repo.clone_from(gitlab_ssh_URL, local_path)
Run Code Online (Sandbox Code Playgroud)
后来我有另一个脚本试图更新这个 repo。
try:
my_repo = git.Repo(local_path)
my_repo .remotes.origin.pull()
except (git.exc.InvalidGitRepositoryError, git.exc.NoSuchPathError):
print("Invalid repository: {}".format(local_path)
Run Code Online (Sandbox Code Playgroud)
这很好用,除非我在中间结帐这样的标签:
tag_id = choose_tag() # Return the position of an existing tag in my_repo.tags
my_repo .head.reference = my_repo.tags[tag_id]
my_repo .head.reset(index=True, working_tree=True)
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我在拉取时收到 GitCommandError:
Run Code Online (Sandbox Code Playgroud)git.exc.GitCommandError: 'git pull -v origin' returned with exit code 1
我已经阅读了两次文档,但我不知道问题出在哪里。特别是因为如果我尝试使用像 SourceTree 这样的专用工具来拉这个 repo,它可以正常工作而不会出现错误或警告。我不明白即使使用分离的 HEAD 签出标记版本的事实如何阻止我拉。
编辑:作为建议,我试图查看 exception.stdout 和 exception.sterr,这里没有任何用处(分别是 b'' 和 None)。这就是为什么我很难理解出了什么问题。
我正在尝试 gitpython,而且我对它很陌生。我正在尝试检测是否有任何需要提交的更改。
目前,我有一个如下所示的函数:
def commit(dir):
r = Repo(dir)
r.git.add(A=True)
r.git.commit(m='commit all')
Run Code Online (Sandbox Code Playgroud)
但这只是提交目录的代码。我想做一些事情,如果有变化,则显示一些消息,否则,显示另一条消息。
有人知道我如何在 python 中做到这一点吗?
我一直在尝试在 aws lambda 中使用gitpython包。我使用的是python2.7环境。我使用它将gitpython与我的 python 代码捆绑到一个 zip 文件中并上传。
import json
import git
def lambda_function(event, context):
repo="https://github.com/abc/xyz.git"
git.Git().clone(repo)
Run Code Online (Sandbox Code Playgroud)
它说
Cmd('git') not found due to: OSError('[Errno 2] No such file or directory')
cmdline: git clone https://github.com/abc/xyz.git: GitCommandNotFound
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 13, in lambda_function
git.Git().clone("https://github.com/abc/xyz.git")
File "/var/task/git/cmd.py", line 425, in <lambda>
return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
File "/var/task/git/cmd.py", line 877, in _call_process
return self.execute(call, **exec_kwargs)
File "/var/task/git/cmd.py", line 602, in execute
raise …Run Code Online (Sandbox Code Playgroud) 我是 GitPython 新手,我想获取存储库的提交数量。我正在寻找 GitPython 中“ git rev-list --count HEAD ”的替代方案,是否有特定的函数可以做到这一点?
我试图获取要显示的存储库的每个提交的列表,然后显示它的大小,但仅显示最后一个提交。感谢您的帮助,问候。
我正在尝试在Windows上安装 git-python 。我尝试使用 git 命令安装它:
pip install gitpython
Run Code Online (Sandbox Code Playgroud)
它安装得很好,并且安装在我的本地应用程序数据中。唯一的问题是当我运行它时,它给了我这个错误:
初始化失败:git 可执行文件错误。必须通过以下方式之一指定 git 可执行文件:
另外我运行了 pip install gitpython:
已满足要求: c:\users\morga\appdata\local\programs\python\python38-32\lib\site-packages 中的 gitpython (3.1.3) 已满足要求: c 中的 gitdb<5,>=4.0.1 :\users\morga\appdata\local\programs\python\python38-32\lib\site-packages (来自 gitpython) (4.0.5) 已满足要求: smmap<4,>=3.0.1 in c:\users \morga\appdata\local\programs\python\python38-32\lib\site-packages (来自 gitdb<5,>=4.0.1->gitpython) (3.0.4)
我没有git的文件夹。我只发现远程 git 的任何内容都在我的本地应用程序数据中
我无法通过导航提交树找到标记指向的提交.对于此特定示例,我使用直接从Github克隆的Tornado Web存储库.
import sys
import git
if len(sys.argv) < 2:
print 'python git_test.py <repo path>'
sys.exit(0)
repo = git.Repo(sys.argv[1])
commits = {}
for git_commit in repo.iter_commits():
commits[git_commit.hexsha] = git_commit
print len(commits)
for git_tag in repo.tags:
print 'Tag %s points to Commit %s' % (
git_tag.name,
commits[git_tag.commit.hexsha]
)
Run Code Online (Sandbox Code Playgroud)
这是假设在git的直接非循环图中找到所有提交,但是,我尝试了另一种方法,通过递归函数递归地导航dag并且它传递了相同的结果.
ian@ian-EP45-UD3L:~/code/playground$ python git_test.py ~/code/tornado/
459
Tag v1.0.0 points to Commit eb5b3d8df7a305ac1ffa0a12c813e5d7ee4d6cd3
Traceback (most recent call last):
File "git_test.py", line 19, in <module>
commits[git_tag.commit.hexsha]
KeyError: '2b5064b7ed962603ade0db0c8e21846a9879e30e'
Run Code Online (Sandbox Code Playgroud)
我做错了什么,我该如何解决这个问题?任何帮助表示赞赏!
我正在使用git-python v0.3.1.
到目前为止,我的代码正在执行以下操作.我想摆脱subprocess.call()的东西
import git
from subprocess import call
repo = git.Repo(repo_path)
repo.remotes.origin.fetch(prune=True)
repo.head.reset(commit='origin/master', index=True, working_tree=True)
# I don't know how to do this using GitPython yet.
os.chdir(repo_path)
call(['git', 'submodule', 'update', '--init'])
Run Code Online (Sandbox Code Playgroud) GitPython 教程提到了属性untracked_files 作为获取特定git存储库中未跟踪文件数组的方式。
但是,引用此属性会导致以下错误。
AttributeError: 'Repo' object has no attribute 'untracked_files'
Run Code Online (Sandbox Code Playgroud)
GitPython中获取未跟踪文件列表的方法是什么?
我有一个回购初始化为
r = git.Repo.init(dirPath)
Run Code Online (Sandbox Code Playgroud)
如何使用gitpython获取该仓库的git config的user.email字段?