拉/取时如何检索文件列表?假设设置上游并拉动上游。
repo = git.Repo('/repo_location/')
result = repo.git.pull()
根据 API 引用,它说返回是可迭代列表。但我无法那样使用它。
如果我执行 print(result)
,它会正确地打印到标准输出,但在我迭代时不会。
最佳答案
我发现没有 gitpython 方法可以执行此操作,所以我执行了 git diff-tree
:
repo = Repo(repo_dir)
# first get the remote information to get all changed files, than pull the repository
# has to be done in this order, because after pulling the local repository does not differ from the remote
repo.remote().fetch()
repo.remote().pull()
# the "-t"-option also lists all changed directories
diff_tree = repo.git.execute('git diff-tree --name-status -t master origin/master')
for line in diff_tree.splitlines():
change_status, file_path = line.split('\t')
关于python - GitPython pull/fetch 检索进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36054492/