2016-07-25 68 views
0

This question涉及如何执行与pygit2的合并,但是,据我所知,这将导致一个新的提交。有没有办法执行rebase,这不会导致一个新的提交,并会简单地快速转发分支引用以对应于给定远程的最新版本?我如何使用pygit2执行rebase?

+0

那不是,严格来说,衍合。这是一个快速合并。 –

+0

@WayneWerner是的,你是对的。我需要使用'pygit2'来将当前分支上的更改应用于远程的同一分支上最新状态的顶部。 – Piotrek

回答

1

您可以用Reference.set_target()快进。

实例(快进masterorigin/master,假设脚本签出master分支开始在干净的状态):

repo.remotes['origin'].fetch() 
origin_master = repo.lookup_branch('origin/master', pygit2.GIT_BRANCH_REMOTE) 
master = repo.lookup_branch('master') 
master.set_target(origin_master.target) 

# Fast-forwarding with set_target() leaves the index and the working tree 
# in their old state. That's why we need to checkout() and reset() 
repo.checkout('refs/heads/master') 
repo.reset(master.target, pygit2.GIT_RESET_HARD) 
+0

会[repo.lookup_branch('origin/branch1',GIT_BRANCH_REMOTE)](http://www.pygit2.org/references.html#pygit2.Repository.lookup_branch)实际从远程获取最新状态('origin'in this案件)? *编辑*:markdown – Piotrek

+0

@Piotrek否,'lookup_branch()'不会获取。你必须显式地获取()。查看更新的答案。 – Leon