英文:
JGit : I want to get all files and folders in a particular branch
问题
我看过很多教程,但没有找到获取特定分支中所有文件和文件夹的代码。
我尝试了这段代码:
File src = new File("C:\\Users\\Winfo\\Documents\\GitHub\\WDAS");
org.eclipse.jgit.lib.Repository repo = new FileRepositoryBuilder().readEnvironment().findGitDir(src).build();
Git git = new Git(repo);
git.checkout()
.setName("new-branch")
.setStartPoint("commit id") // 在这里填入提交的id
.call();
这会基于提交的id创建一个单独的分支,但我需要根据分支在本地存储库中克隆文件和文件夹列表。
我对JGit不太熟悉,有人可以帮忙满足我的需求吗?提前感谢。
英文:
I have seen a lot of tutorials but I haven't found any code for getting all the files and folders in a particular branch.
I have tried this piece of code
File src = new File("C:\\Users\\Winfo\\Documents\\GitHub\\WDAS");
org.eclipse.jgit.lib.Repository repo = new FileRepositoryBuilder().readEnvironment().findGitDir(src).build();
Git git = new Git(repo);
git.checkout()
.setName("new-branch")
.setStartPoint("commit id") // commit id here
.call();
This is creating a separate Branch based on the commit id, but I need to clone the list of files and folders in a local repository based on the branch.
I am new to JGit, could someone help with my requirement. Thanks in advance
答案1
得分: 0
你可以像下面这样执行操作来从特定分支进行拉取:
Git.cloneRepository()
.setURI("https://github.com/eclipse/jgit.git") // 你的 Git URL
.setDirectory(new File("/path/to/repo"))
.setBranchesToClone(Arrays.asList("refs/heads/specific-branch")) // 提供你的分支名称
.setBranch("refs/heads/specific-branch")
.call();
更多信息请参阅:这里
英文:
You may do something like this below to pull from a particular branch
Git.cloneRepository()
.setURI("https://github.com/eclipse/jgit.git") // your git url
.setDirectory(new File("/path/to/repo"))
.setBranchesToClone(Arrays.asList("refs/heads/specific-branch"))// give ur branch name
.setBranch("refs/heads/specific-branch")
.call();
For more information: read here
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论