I have a GitHub repository and I would like to make a copy of that repository at every commit throughout the history of that repository without altering it. I've been using the GitPython package in Python, and here is what I have so far:
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)
However, this doesn't work -- it simply clones the repo (the final one) such that I get many copies of the same thing. Essentially repo.clone()
is simply taking renaming each copy for the specified sha
rather than using it as a unique identifier. There is another function repo.clone_from()
that should take the URL as an argument, but I don't know how to retrieve the URL of a specific commit.
Maybe using -bash
commands is a better way to do this?