git rebase
withを実装しようとして立ち往生してい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
。
その他の SO の質問 ( hereおよびhere ) では、早送りマージについて説明していますが、適切なリベースについては説明していません。