Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用JGIT从git存储库克隆单个文件_Java_Jgit - Fatal编程技术网

Java 如何使用JGIT从git存储库克隆单个文件

Java 如何使用JGIT从git存储库克隆单个文件,java,jgit,Java,Jgit,我使用了下面的代码来克隆我的存储库,它工作得很好 public static void getCodeBase() throws Exception { String url="https://urltogitrepository"; String destination = ".//clone3//"; Git.cloneRepository().setURI(url) .setDirectory

我使用了下面的代码来克隆我的存储库,它工作得很好

  public static void getCodeBase() throws Exception 
     {
        String url="https://urltogitrepository";
        String destination = ".//clone3//";   
        Git.cloneRepository().setURI(url)
              .setDirectory(Paths.get(destination).toFile()).call();
        System.out.println("Cloned successfully....");

     }

但是我只想从git存储库下载一个java文件,而不是克隆整个repo。但我不知道我该怎么做

下面的代码对我来说很好:

Git repo = Git.cloneRepository()
          .setURI(url)
          .setDirectory(destination))
          .setBranchesToClone(Arrays.asList("refs/heads/master"))
          .setCloneAllBranches(false)
          .setCloneSubmodules(true)
          .setNoCheckout(true)
          .call();

         repo.checkout().setStartPoint("origin/master").addPath("file1.txt").call();

您是否正在寻找
TreeWalk
RevWalk
来检查给定的存储库,或者您是否可以选择仅下载git存储库中文件的
raw
内容?现在代码克隆了整个repo。我不想克隆所有我只想做的选定文件。可能是该存储库中可用的配置文件或excel文件。这是我的要求。Git存储库(与大多数其他分布式SCM系统一样)需要存储库的本地副本才能访问内容。因此,您在问题中发布的克隆步骤是必要的。它非常有用。但我有时间限制在repo中克隆整个文件。大多数情况下需要8-10分钟以上。这就是为什么检查是否有可能只克隆100kb大小的文件。与其克隆整个存储库,不如使用REST API获取单个文件的原始内容。例如,或允许您这样做。欢迎使用SO!当你用代码回答问题时,试着解释一下。