使用pygit2从远程拉出的步骤 [英] Steps for pulling from remote using pygit2
问题描述
使用pygit2库时,一个简单的repo.fetch()会获取所有差异.
答案此处描述了步骤viz
1. Remote.fetch()
2. Repository.create_reference()
或Reference.target=
3. Repository.checkout_head()
我不确定第二步到底发生了什么以及需要传递什么参数.
r.repo.create_reference: (self, name, target, force=False)
创建一个指向对象或另一个对象的新引用名称"
参考.根据目标参数的类型和值,此方法尝试
猜测它是直接引用还是符号引用.关键字参数:
力
如果True引用将被覆盖,否则(默认)是一个
引发异常.示例::
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')
第二步中发生的事情以及Reference.target=
的含义
它应该指向哪里?
以及所有这些如何使用Remote.fetch()
动作?
refs/heads/master":这是一个简单的文件,带有引用,必须包含该引用,以便该分支指向(引用)另一个分支SHA1.> While using the pygit2 library a simple repo.fetch() fetches all the diffs.
The answer here describes the steps viz I am not sure about what is happening under the hood in second step and what parameters need to be passed.
1. Remote.fetch()
2. Repository.create_reference()
or Reference.target=
3. Repository.checkout_head()
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?
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.
这篇关于使用pygit2从远程拉出的步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!