如何使用libgit2克隆/获取git存储库? [英] How to clone/fetch a git repository with libgit2?

查看:176
本文介绍了如何使用libgit2克隆/获取git存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要初始化一个git仓库,并将最新版本的分支存入其中。在bash中,命令是:

  git init 
git remote add -t $ BRANCH -f origin $ REMOTE

我试图用libgit2以编程方式执行相同的操作,但无法找到第二个线。创建远程的调用很明显,但我没有看到任何将其添加到存储库或处理分支。

是否可以使用libgit2 ?如果没有,是否有库能够做到这一点?

解决方案

描述如何在libgit2中实现读取过程的高级步骤找到 此处



您可以找到执行此类任务的代码示例 here 此处 即可。请注意,这些代码片段会检索所有较新的提交(一个分支)。

只是指向特定提交的指针)。



到目前为止,还没有办法在libgit2中执行结账。

假设您需要更多帮助,我推荐以下两个地方:


  • libgit2邮件列表(通过libgit2@librelist.com)

  • libgit2 问题跟踪器



更新



克隆功能刚刚 合并 到libgit2存储库中。
$ b



作为拉取请求的一部分,作者还负责为用户提供签出实现。




I need to initialize a git repository and fetch the latest version of a branch into it. In bash, the commands are:

git init
git remote add -t $BRANCH -f origin $REMOTE

I'm trying to do the same programmatically with libgit2, but am having trouble finding the equivalent for the second line. The calls to create a remote are apparent, but I'm not seeing any to add it to a repository or handle the branch.

Is it possible to do this with libgit2? If not, is there a library capable of doing this?

解决方案

High level steps describing how to implement a fetching process in libgit2 can be found here.

You can find example of codes performing such task here and here. Beware these examples might get a little out of sync as the API is moving on.

Please note that those pieces of code will retrieve all newer commits (a branch is only a pointer to a specific commit) from the upstream defined remote.

As of today, there's no way to perform a checkout in libgit2 yet.

Provided you need some more help, I'd recommend those two places:

  • the libgit2 mailing list (via libgit2@librelist.com)
  • the libgit2 issue tracker

Update

The clone feature has just been merged into the libgit2 repository.

As part of the pull request, the author took care of providing the users with a checkout implementation as well.

这篇关于如何使用libgit2克隆/获取git存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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