java - 如何使用 JGIT 从 git 存储库中克隆单个文件
问题描述
我使用下面的代码来克隆我的存储库,它工作正常。
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();
推荐阅读
- android - React Native for android 中的延迟深度链接
- python - 如何在课堂上传递参数?
- java - 如何将 concurentHashMap 转换为 Guava Cache
- agda - 我如何找到比边界条件更进一步的约束?
- r - R程序计算相同实验结果的平均值
- django - 如何更改 django 中的日期字段?
- bash - lowriter Bash 脚本将所有 doc 就地转换为 pdf
- dsl - xtext 中的高级参考分辨率,如何正确自定义范围/索引?
- git - 无法执行子模块更新
- ldap - 我可以将 SCM-Manager 中的现有用户转换为不同的类型吗?