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

时间:2017-08-01 18:58:09

标签: 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 = 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_from()应该将URL作为参数,但我不知道如何检索特定提交的URL。

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

0 个答案:

没有答案