Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
gitpython创建zip归档_Python_Git_Gitpython - Fatal编程技术网

gitpython创建zip归档

gitpython创建zip归档,python,git,gitpython,Python,Git,Gitpython,如何使用gitpython创建归档文件,我尝试了以下创建文件的方法,但无法打开它它告诉我读取归档文件时出错该归档文件似乎无效或已损坏 from git import * repo = Repo(repo_path) assert repo.bare == False repo.archive(open("repo.tar",'w')) 我想创建一个zip文件,所以我尝试了这个方法,但在这里它创建了一个空的zip文件(repo的路径与我使用repo.clone it propery克隆所有内容时

如何使用gitpython创建归档文件,我尝试了以下创建文件的方法,但无法打开它它告诉我读取归档文件时出错该归档文件似乎无效或已损坏

from git import *
repo = Repo(repo_path)
assert repo.bare == False
repo.archive(open("repo.tar",'w'))
我想创建一个zip文件,所以我尝试了这个方法,但在这里它创建了一个空的zip文件(repo的路径与我使用repo.clone it propery克隆所有内容时一样正确)


您需要以二进制方式打开文件(将
b
添加到
模式
参数中),并在完成后将其关闭。通过对示例进行以下修改,可以使其正常工作:

from git import Repo

repo = Repo(repo_path)
assert not repo.bare
with open('repo.zip', 'wb') as archive_file:
    repo.archive(archive_file, format='zip')
from git import Repo

repo = Repo(repo_path)
assert not repo.bare
with open('repo.zip', 'wb') as archive_file:
    repo.archive(archive_file, format='zip')