Is partial checkout supported by JGit 3.7?

萝らか妹 提交于 2019-11-28 06:50:21

问题


I am using Jgit 3.7 for importing files from Git repository. But I would like to import only set of folders instead of all. I know Git supports this, but I would like to know Jgit 3.7 supports the same? If so, can someone guide me.


回答1:


By design, a cloned git repository always contains all files and folders of the original repository.

With native git, you can create a shallow clone (git clone --depth 1 ...) but this feature is not yet implemented in JGit.

Contradicting its general design, native git (since version 1.7) lets you create partial clones with sparse checkouts but this is also not possible out-of-the-box in JGit.

What you can do in JGit though - once you have cloned a repository - is to checkout only some files of a branch or commit.

git.checkout().setStartPoint( "some-branch" ).addPath( "path/to/file" ).call()



回答2:


Based on @rüdiger-herrmann's answer:

String url = "https://github.com/renaud/solr_noLenghNormSimilarity";
String hash = "802558f58add3a1f5b33f04254194bd7cd59b27f";
String subPath = "src/org";
String dest = "myclone";

File localPath = new File(dest);

Git gitRepo = Git.cloneRepository().setURI(url).setDirectory(localPath).setNoCheckout(true).call();
gitRepo.checkout().setStartPoint(hash).addPath(subPath).call();
gitRepo.getRepository().close();


来源:https://stackoverflow.com/questions/29505919/is-partial-checkout-supported-by-jgit-3-7

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!