pygit2中的Repository.checkout()和Repository.checkout_head()有什么区别? [英] What is the difference between Repository.checkout() and Repository.checkout_head() in pygit2?

查看:182
本文介绍了pygit2中的Repository.checkout()和Repository.checkout_head()有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从远程提取并整合更改使用pygit2,最后一步是使用 Repository.checkout() Repository.checkout_head()。使用哪个?

这两种方法都以退出策略为参数。
现在有几个策略用于检出GIT_CHECKOUT_SAFE,GIT_CHECKOUT_SAFE_CREATE,GIT_CHECKOUT_FORCE 等$ 我正面临的问题是,即使在检查出索引文件被修改后,即有一些文件在它上演。




r.repo.status()

{'README.md': 2}




使用策略GIT_CHECKOUT_FORCE时,索引为空并且提交也被存储。

何时应该使用GIT_CHECKOUT_FORCE策略?

以下是该过程的逐步代码:<
r.repo 是Repository对象。 remo 是名称 ssh-sansa

 >>> r.repo.status()
{}
>>> z = remo.fetch()
>>> remoref = r.repo.lookup_reference('refs / remotes / ssh-sansa / master')
>>> rref = r.repo.lookup_reference(r.ref)
>>> r.ref
'refs / heads / master'
>>> remoref.target.hex
'23aac24f65c775d0524095d422133c63caf3826a'
>>> rref.target.hex
'29f5f99722e9c93a58ec085a55c6a4814c4adffb'
>>> rref.target = remoref.target.hex
>>> rref.target.hex
'23aac24f65c775d0524095d422133c63caf3826a'
>>> r.repo.status()
{'README.md':2}
>>> r.repo.checkout_head(repo_.pygit2.GIT_CHECKOUT_SAFE_CREATE)
>>> r.repo.status()
{'README.md':2}
>>> r.repo.checkout('HEAD',strategy = repo_.pygit2.GIT_CHECKOUT_SAFE_CREATE)
>>> r.repo.status()
{'README.md':2}
>>> r.repo.checkout('HEAD',strategy = repo_.pygit2.GIT_CHECKOUT_FORCE)
>>> r.repo.status()
{}

注意:这是一个跟进问题使用pygit2提取和整合变更另一个问题在这里

解决方案

没有区别。如果您将'HEAD' refname 传递给 Repository.checkout(),它会调用 Repository.checkout_head()



至于文件保持修改的原因,这是因为你已经告诉图书馆不要覆盖更改。请参阅策略文档,了解每种策略的用途。特别是,


在这些之间是GIT_CHECKOUT_SAFE和GIT_CHECKOUT_SAFE_CREATE,两者都只进行修改,不会丢失更改。


当文件被修改时,覆盖它会导致我们失去更改,因此它拒绝。如果您想覆盖它,请使用 FORCE 或导致文件不处于修改状态。


When pulling and integrating changes from remote with pygit2, the last step is to checkout using Repository.checkout() or Repository.checkout_head(). Which to use?

Both of these take a checking out strategy as an argument. Now there are a couple of strategies for checking out viz GIT_CHECKOUT_SAFE, GIT_CHECKOUT_SAFE_CREATE, GIT_CHECKOUT_FORCE etc.
The problem I am facing is that even after checking out the index file is modified ie there are a couple of files in it that are staged.

r.repo.status()
{'README.md': 2}

When using the strategy GIT_CHECKOUT_FORCE the indexed is empty and the commits are also being stored.

When should GIT_CHECKOUT_FORCE strategy not be used?
Here is the step by step code of the process:
r.repo is Repository object. remo is the remote with name ssh-sansa

>>> r.repo.status()
{}
>>> z = remo.fetch()
>>> remoref = r.repo.lookup_reference('refs/remotes/ssh-sansa/master')
>>> rref = r.repo.lookup_reference(r.ref)
>>> r.ref
'refs/heads/master'
>>> remoref.target.hex
'23aac24f65c775d0524095d422133c63caf3826a'
>>> rref.target.hex
'29f5f99722e9c93a58ec085a55c6a4814c4adffb'
>>> rref.target=remoref.target.hex
>>> rref.target.hex
'23aac24f65c775d0524095d422133c63caf3826a'
>>> r.repo.status()
{'README.md': 2}
>>> r.repo.checkout_head(repo_.pygit2.GIT_CHECKOUT_SAFE_CREATE)
>>> r.repo.status()
{'README.md': 2}
>>> r.repo.checkout('HEAD',strategy=repo_.pygit2.GIT_CHECKOUT_SAFE_CREATE)
>>> r.repo.status()
{'README.md': 2}
>>> r.repo.checkout('HEAD',strategy=repo_.pygit2.GIT_CHECKOUT_FORCE)
>>> r.repo.status()
{}

Note: This is a follow up question to pulling and integrating changes using pygit2 and another question here

解决方案

There is no difference. If you pass a refname of 'HEAD' to Repository.checkout(), it will call Repository.checkout_head().

As to why the file remains modified, it is because you've told the library not to overwrite changes. See the strategy docs for a description of what each strategy does. Specifically,

In between those are GIT_CHECKOUT_SAFE and GIT_CHECKOUT_SAFE_CREATE both of which only make modifications that will not lose changes.

As your file is modified, overwriting it would cause us to lose changes and hence it refuses to. If you want to overwrite it, then use FORCE or cause the file not to be in a modified state.

这篇关于pygit2中的Repository.checkout()和Repository.checkout_head()有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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