从远程git存储库获取单个文件 [英] Get a single file from a remote git repository

查看:430
本文介绍了从远程git存储库获取单个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 我更喜欢使用一个解决方案尽可能少的带宽,最好只下载单个文件。我不需要浏览存储库,我已经有文件的路径。

  2. 我更喜欢不依赖于其他应用程序的解决方案(例如在机器上安装另一个git客户端) 。一个包含git客户端实现本身的Java库将是最佳的。

我可以使用Subversion =http://www.svnkit.com/ =noreferrer> SVNKit ,我看到有一个纯java实现的git( eclipse的JGit ),可能会做类似的事情,所以我希望有一个积极的答案;虽然从我了解git的工作原理 - 只允许从本地存储库更新 - 这可能是有问题的。

解决方案

git不是真正设计用于远程存储库的单个文件访问,但您可以滥用 git archive 。缺点是你必须下载一个树,而不仅仅是你需要的blob。



例如

  git archive --remote = url://to.git.repo branch path / to / dir | tar -x文件

另外,如果您在远程存储库中设置了gitweb,可以使用一个简单的卷曲或wget命令以其原始格式下载任何文件。


Is there a way to programmatically download a single file from a remote git repository, in Java?

  1. I prefer a solution which uses as little bandwidth as possible, preferably only downloading that single file. I do not need to browse the repository, I already have the file's path.
  2. I prefer a solution which does not depend on other applications (e.g. an installation of another git client on the machine). A Java library which contains a git client implementation itself would be optimal.

I was able to do something similar with Subversion using SVNKit and I've seen there is a pure java implementation of git (eclipse's JGit) which might be able to do something similar, so I hope there is a positive answer; though from what I understand about how git works - allowing updates only from local repositories - this could prove to be problematic.

解决方案

git isn't really designed for single file access from a remote repository but you can abuse git archive for this. The downside is that you have to download a "tree" rather than just the blob that you need.

E.g.

git archive --remote=url://to.git.repo branch path/to/dir | tar -x file

As an alternative, if you have gitweb set up on the remote repository you can use a simple curl or wget command to download any file in its "raw" format.

这篇关于从远程git存储库获取单个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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