我一直试图用git rebase
来实现pygit2
。
假设此回购历史记录,如何使用topic
在master
上重新pygit2
? (即相当于git rebase master topic
):
A---B---C topic
/
D---E---F---G master
根据pygit2 documentation,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
。