我在正在使用的脚本中运行以下代码。
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()
。也就是说,即使那部分代码确实运行了,拉动仍然不会进行。
此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
,它应该可以工作。