我如何使用pygit2执行rebase? [英] How can I perform a rebase with pygit2?

查看:182
本文介绍了我如何使用pygit2执行rebase?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

可以与参考快进。 set_target()


$ b 示例(快速转发 master 原点/ master ,假设脚本从干净状态的 master 分支中检出):

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' repo.lookup_branch('master')
master.set_target(origin_master.target)

#使用set_target()进行快速转发会使索引和工作树
#旧州。这就是为什么我们需要checkout()和reset()
repo.checkout('refs / heads / master')
repo.reset(master.target,pygit2.GIT_RESET_HARD)
code>


This question touches on how to perform a merge with pygit2, but, to the best of my understanding, that will result in a new commit. Is there a way to perform a rebase, which will not result in a new commit and will simply fast-forward the branch reference to correspond to the latest from a given remote?

解决方案

You can fast-forward with Reference.set_target().

Example (fast-forwarding master to origin/master, assuming that the script starts from checked out master branch in clean state):

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)

这篇关于我如何使用pygit2执行rebase?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆