简体   繁体   English

在JGit中使用远程存储库

[英]Working with a remote repository in JGit

I am working on a project where we have to use JGit. 我正在开发一个我们必须使用JGit的项目。 I have a problem when I try to work with a remote git repository (the git that is not cloned in my local device) I receive the following exception: 当我尝试使用远程git存储库(未在我的本地设备中克隆的git)时遇到问题我收到以下异常:

No HEAD exists and no explicit starting revision was specified 没有HEAD存在且未指定明确的起始修订版

If I clone the repository it works well, but repositories are quite big and I cannot clone it because of project requirements. 如果我克隆存储库它运行良好,但存储库非常大,我无法克隆它因为项目要求。 Is there a way how to work with remote repositories? 有没有办法如何使用远程存储库? I do only simple read operations. 我只做简单的读操作。

In order to access the history of a Git repository you need to clone it first. 要访问Git存储库的历史记录,您需要先克隆它。 The clone may be bare if you are not interested in the working dir, but a clone is required. 如果您对工作目录不感兴趣,则克隆可能是裸的,但需要克隆。

Git allows to create a shallow clone that includes only the history up to a specified depth, however JGit still lacks support for shallow clones: https://bugs.eclipse.org/bugs/show_bug.cgi?id=475615 Git允许创建一个浅层克隆,其中只包含指定深度的历史记录,但JGit仍然缺乏对浅层克隆的支持: https ://bugs.eclipse.org/bugs/show_bug.cgi?id = 475615

JGit supports to walk the refs (ie tags, branches, ...) that are available remotely, see eg https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/porcelain/ListRemoteRepository.java JGit支持遍历远程可用的refs(即标签,分支......),例如https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler /jgit/porcelain/ListRemoteRepository.java

Then you might be able to only fetch part of the repository if you provide appropriate RefSpecs. 然后,如果提供适当的RefSpec,您可能只能获取部分存储库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM