Steps for pulling from remote using pygit2

[亡魂溺海] 提交于 2020-02-23 04:47:07

问题


While using the pygit2 library a simple repo.fetch() fetches all the diffs. The answer here describes the steps viz
1. Remote.fetch()
2. Repository.create_reference() or Reference.target=
3. Repository.checkout_head()

I am not sure about what is happening under the hood in second step and what parameters need to be passed. r.repo.create_reference: (self, name, target, force=False)

Create a new reference "name" which points to an object or to another
reference.

Based on the type and value of the target parameter, this method tries
to guess whether it is a direct or a symbolic reference.

Keyword arguments:

force
If True references will be overridden, otherwise (the default) an
exception is raised.

Examples::

repo.create_reference('refs/heads/foo', repo.head.target)
repo.create_reference('refs/tags/foo', 'refs/heads/master')
repo.create_reference('refs/tags/foo', 'bbb78a9cec580')

What is happening in the second step and what is meant by Reference.target= Where should it point to? And how does all this use the Remote.fetch() action?


回答1:


The create_reference method changes the target in order for said target to contains (reference) the name.

Here, after a fetch, you would want to set the reference of the local branch (you want to checkout) to the right remote tracking branch (you just fetched):

repo.create_reference('refs/remotes/origin/master', 'refs/heads/master')

You can look up the file "refs/heads/master" in your .git folder: it is a simple file with the reference it has to contain in order for that branch to point to (reference) another branch SHA1.



来源:https://stackoverflow.com/questions/24646004/steps-for-pulling-from-remote-using-pygit2

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