通过pygit2拉取和集成远程更改 [英] pulling and integrating remote changes with pygit2

查看:142
本文介绍了通过pygit2拉取和集成远程更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题。我正在编写一个脚本,用于搜索文件夹中的存储库,查找网络上的远程并将所有新数据拖入存储库,通知我有关新更改。主要想法很清楚。我在Windows 7 x64上使用python 2.7,使用pygit2来访问git功能。命令行支持简单的命令git pull'origin',但是git api更复杂,我看不到方向。好吧,我来了那么远:
import pygit2
orepository = pygit2.Repository(path / to / repository / .git)
oremote = repo.remotes [ 0]
result = oremote.fetch()

此代码检索新对象并将其下载到存储库中,但不更新主分支或检查新数据出。通过使用TortoiseGit检查存储库,我发现没有办法检出,即使在显示日志时也不会显示新的日志消息。我需要使用git pull命令刷新存储库和工作副本。现在我的问题是:我需要做什么来通过使用pygit2来完成所有这些?我的意思是,我通过提取它们来下载更改,但是我需要做什么?我想更新主分支和工作副本...
先谢谢您帮助解决我的问题。
最好的问候。

解决方案

Remote.fetch()不会更新workdir中的文件,因为它离它的工作很远。如果您想更新当前分支并检出这些文件,您还需要通过 Repository.create_reference() Reference.target执行这些步骤= 取决于您当时拥有的数据,然后例如 Repository.checkout_head()如果您决定更新。


$ b

git-pull 是一个脚本,根据传递的配置和标志执行很多不同的步骤。当你正在编写一个工具来模拟多个存储库时,你需要弄清楚你想要做什么,而不是希望所有的东西都被设置为使得 git-pull 不会让你感到惊讶。


I do have the following problem. I'm writing a script which searches a folder for repositories, looks up the remotes on the net and pulls all new data into the repository, notifying me about new changes. The main idea is clear. I'm using python 2.7 on Windows 7 x64, using pygit2 to access the git features. The command-line supports the simple command "git pull 'origin'", but the git api is more complicated and I don't see the way. Okay, I came that far: import pygit2 orepository=pygit2.Repository("path/to/repository/.git") oremote=repo.remotes[0] result=oremote.fetch() This code retrieves the new objects and downloads it into the repository, but doesn't update the master branch or check the new data out. By inspecting the repository with TortoiseGit I see that nothing way checked out , even the new log messages don't appear when showing the log. I need to use the git pull command to refresh the repository and working copy at all. Now my question: What do I need to do to do all that by using pygit2? I mean, I download the changes by fetching them, but what do I need to do then? I want to update the master branch and working copy too... Thank you in advance for helping me with my problem. Best Regards.

解决方案

Remote.fetch() does not update the files in the workdir because that's very far from its job. If you want to update the current branch and checkout those files, you need to also perform those steps, via Repository.create_reference() or Reference.target= depending on what data you have at the time, and then e.g. Repository.checkout_head() if you did decide to update.

git-pull is a script that performs very many different steps depending on the configuration and flags passed. When you're writing a tool to simulate it over multiple repositories, you need to figure out what it is that you want to do, rather than hoping everything is set up just so that git-pull won't surprise you.

这篇关于通过pygit2拉取和集成远程更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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