Skip to content

Instantly share code, notes, and snippets.

@severin-lemaignan
Created October 14, 2016 16:35
Show Gist options
  • Save severin-lemaignan/f8d783514376152d70f29b32e2375970 to your computer and use it in GitHub Desktop.
Save severin-lemaignan/f8d783514376152d70f29b32e2375970 to your computer and use it in GitHub Desktop.
Rebase with pygit2
# Purpose: rebase 'other' on top of 'master'
branchc = repo.lookup_branch("other")
branchb = repo.lookup_branch("master")
base = repo.merge_base(branchb.target, branchc.target)
treeb=repo.get(branchb.target).tree
treec=repo.get(branchc.target).tree
base_tree = repo.get(base).tree
repo.checkout(branchb)
index=repo.merge_trees(base_tree,treeb,treec)
tree_id = index.write_tree(repo)
repo.create_commit(branchc.name, sig, sig, "blah", tree_id, [branchb.target])
#---------------------------------------------------------------------------
#GitError Traceback (most recent call last)
#<ipython-input-33-f3577ddcf5b0> in <module>()
#----> 1 repo.create_commit(branchc.name, sig, sig, "blah", tree_id, [branchb.target])
#
#GitError: failed to create commit: current tip is not the first parent
@aldrinrayen
Copy link

since its already committed so its not the parent give the parent if you already committed else leave it blank

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment