如何使用pygit2执行rebase?

时间:2016-07-25 21:10:24

标签: python git pygit2

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

1 个答案:

答案 0 :(得分: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)