如何通过pygit2进行git合并 [英] How to make a git merge by pygit2

查看:138
本文介绍了如何通过pygit2进行git合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将分支合并到master:

  repo = pygit2.Repository(/ path / to / repo / )
branch = repo.lookup_branch(upstream / branch,pygit2.GIT_BRANCH_REMOTE)
oid = branch.target
merge_result = repo.merge(oid)

并且merge_result包含ff oid(如

接下来我应该做些什么来更改资料库?

合并函数进行合并(或者在本例中告诉你可以跳过它),但是它取决于你(或者这个工具的用户)是否要将当前分支移动到新位置。



这样做与其他任何时候想要更改引用的时间相同。在这种情况下,您希望通过将 HEAD 解析为非符号引用并设置其目标,从而访问当前分支。

  repo.lookup_reference('HEAD')。resolve()。target = merge_result.fastforward_oid 


I try to merge branch into master:

repo = pygit2.Repository("/path/to/repo/")
branch = repo.lookup_branch("upstream/branch", pygit2.GIT_BRANCH_REMOTE)
oid = branch.target
merge_result = repo.merge(oid)

And merge_result contains ff oid (as in documentaion) and repo hasn't changed.

What should I do next to change the repository?

解决方案

The merge function does the merge (or in this case tells you you could skip it), but it's up to you (or the user of the tool) whether you want to move the current branch to the new position.

Doing that is the same as any other time you want to change a reference. In this case you want to get to the current branch, which you do via resolving HEAD to a non-symbolic reference and setting its target.

repo.lookup_reference('HEAD').resolve().target = merge_result.fastforward_oid

这篇关于如何通过pygit2进行git合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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