在Python中使用GitPython包克隆特定提交

在Python中使用GitPython包克隆特定提交,python,Python,我有一个GitHub存储库,我希望在该存储库的历史记录中,每次提交时都复制该存储库,而不改变它。我一直在Python中使用GitPython包,到目前为止,我已经做到了以下几点: from git import * import os for file in os.listdir(folder)[1:len(os.listdir(folder))]: directory = folder + file # create repo object for each team repo =

我有一个GitHub存储库,我希望在该存储库的历史记录中,每次提交时都复制该存储库,而不改变它。我一直在Python中使用GitPython包,到目前为止,我已经做到了以下几点:

from git import *
import os    

for file in os.listdir(folder)[1:len(os.listdir(folder))]:
directory = folder + file

# create repo object for each team
repo = Repo(directory)

# list of all commits in the repo
commits = list(repo.iter_commits('master'))
for c in commits:
    # unique SHA key
    sha = c.name_rev.split()[0] 
    repo.clone(sha)
然而,这不起作用——它只是复制了回购协议(最终的回购协议),这样我就可以得到许多相同内容的副本。实际上,
repo.clone()
只是为指定的
sha
重命名每个副本,而不是将其用作唯一标识符。还有另一个函数
repo.clone\u from()
,它应该将URL作为参数,但我不知道如何检索特定提交的URL


也许使用
-bash
命令是一种更好的方法?

您应该能够克隆,然后对特定的sha进行硬重置。@ADIZ004就像使用bash命令一样?查看此链接@ADIZ004
repo.head.reset('head~1',index=True,working\u tree=True)
一直工作到我提交合并为止。有没有办法解决这个问题,因为我只想遍历主分支上的命令?我收到以下错误:
stderr:“致命:未能将“HEAD~1”解析为有效修订版。”
您应该能够克隆,然后对特定的sha进行硬重置。@adiaz004就像使用bash命令一样?查看此链接@adiaz004
repo.HEAD.reset('HEAD~1',index=True,working\u tree=True)
已启动,直到我达到合并的提交。有没有办法解决这个问题,因为我只想遍历主分支上的命令?我收到以下错误:
stderr:“致命:无法将'HEAD~1'解析为有效修订版。”