我一直在尝试实现git rebase
with pygit2
。
假设这个回购历史,如何重新topic
使用?(即,等价于):master
pygit2
git rebase master topic
A---B---C topic
/
D---E---F---G master
根据pygit2 文档,merge_trees
可用于此目的。到目前为止,我得到了:
import pygit2 as git
repo = git.Repository(".")
master = repo.lookup_branch("master")
topic = repo.lookup_branch("topic")
base = repo.merge_base(master.target, topic.target)
master_tree = repo.get(master.target).tree
topic_tree = repo.get(topic.target).tree
base_tree = repo.get(base).tree
index = repo.merge_trees(base_tree,topic,master)
tree_id = index.write_tree(repo)
sig = git.Signature('FooBar', 'foo@bar.org')
# this is not going to work -> several commits need to be re-created
repo.create_commit(topic.name,sig,sig,"msg?",tree_id,[master.target])
这失败并出现错误GitError: failed to create commit: current tip is not the first parent
。