如何使用pygit2进行改造?

时间:2016-10-17 08:23:20

标签: python git pygit2

我一直试图用git rebase来实现pygit2

假设此回购历史记录,如何使用topicmaster上重新pygit2? (即相当于git rebase master topic):

      A---B---C topic
     /
D---E---F---G master

根据pygit2 documentationmerge_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

其他SO问题(herehere)讨论了快进合并但没有正确的变更。

0 个答案:

没有答案