Created
November 7, 2014 21:09
-
-
Save xhacker/dc02b27caf9d1d46a539 to your computer and use it in GitHub Desktop.
Clone only the history of a repo into a new repo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygit2 | |
from pygit2 import GIT_SORT_TOPOLOGICAL, GIT_SORT_REVERSE | |
repo = pygit2.Repository("/path/to/the/repo") | |
hist_repo = pygit2.Repository("/path/to/the/repo/for/the/history") | |
parents = [] | |
for commit in repo.walk(repo.head.target, | |
GIT_SORT_TOPOLOGICAL | GIT_SORT_REVERSE): | |
print "[Duplicating] " + commit.message, | |
tree = hist_repo.TreeBuilder().write() | |
oid = hist_repo.create_commit( | |
'refs/heads/master', | |
commit.author, | |
commit.committer, | |
commit.message, | |
tree, | |
parents) | |
parents = [oid] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment