从Jgit中的远程分支拉出

问题描述 投票:1回答:1

我在正在使用的脚本中运行以下代码。

 Git git = Git.open(repoLocation);
 Repository repo = git.getRepository();
 PullResult result = git.pull()
                        .setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, password))
                        .setRemote("origin")// Is this right?
                        .setRemoteBranchName("feature/myBranch")// Is this right?
                        .call();

但是,我无法从名为“ myBranch”的远程功能分支中提取。如何通过Jgit从该远程分支中拉出?

编辑:通过查看堆栈跟踪,错误来自稍后几行,我称之为git.close()。也就是说,即使那部分代码确实运行了,拉动仍然不会进行。

java git jgit
1个回答
0
投票

tech blog给出以下有关如何处理Jgit中分支的示例:

// Create a new branch
git.branchCreate().setName("newBranch").call();
// Checkout the new branch
git.checkout().setName("newBranch").call();
// List the existing branches
List<Ref> listRefsBranches = git.branchList().setListMode(ListMode.ALL).call();
for (Ref refBranch : listRefsBranches) {
System.out.println("Branch : " + refBranch.getName());
}
// Go back on "master" branch and remove the created one
git.checkout().setName("master");
git.branchDelete().setBranchNames("newBranch");

尝试执行git.fetch().setRemote("origin").call();,然后执行git.checkout().setName("newBranch").call();,然后再执行git pull,它应该可以工作。

© www.soinside.com 2019 - 2024. All rights reserved.