How to make a git merge by pygit2

£可爱£侵袭症+ 提交于 2019-12-01 12:45:39

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/21661211/how-to-make-a-git-merge-by-pygit2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!