简体   繁体   English

如何使用JGit检出某个文件夹

[英]How to checkout a certain folder with JGit

FetchResult fr = git.fetch().setCredentialsProvider(credentials).setCheckFetchedObjects(true).Call();
git.checkout().setCreateBranch(true).setName("origin/" + branchName).setStartPoint("origin/" + branchName + "path/to/folder").call()

This is the code I'm using to check out a single folder from a remote repository. 这是我用来从远程存储库检出单个文件夹的代码。 Equivalent git commands are: 等效的git命令是:

git fetch origin
git checkout origin/branch -- path/to/folder

But, the Java code doesn't work for me, I was only able to initialise the local repository and configure remote repository. 但是,Java代码对我不起作用,我只能初始化本地存储库并配置远程存储库。 The checkout didn't work and I couldn't find out what mistake I'm making. 结帐无效,我找不到我犯的错误。

Try making changes in the checkout part like this 尝试像这样在结帐部分进行更改

"origin/"

and give it a try. 并尝试一下。

Otherwise you want to do is a sparse checkout 否则,您要做的是sparse checkout

How do I implement sparse checkout in JGit? 如何在JGit中实施稀疏签出?

In order to check out a particular folder with JGit (a sparse checkout), you need to tell the CheckoutCommand which folder to check out. 为了使用JGit检出特定文件夹(稀疏检出),您需要告诉CheckoutCommand哪个文件夹。

For example: 例如:

git.checkout().setName( "branch-to-check-out" ).addPath( "path/to/folder" ).call();

addPath() can be called multiple times to check out each of the given paths. 可以多次调用addPath()以检出每个给定路径。 The path is interpreted relative to the work directory. 相对于工作目录解释路径。

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

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