我正在使用以下代碼從github簽出存儲庫。JGit分支結帳問題
private String url = "https://github.com/organization/project.git";
Git repo = Git.cloneRepository().setURI(url).setDirectory(directory).setCloneAllBranches(true).call();
for (Ref b : repo.branchList().call()) {
System.out.println("(standard): cloned branch " + b.getName());
}
我使用的代碼
Git git = Git.open(checkout); //checkout is the folder with .git
git.pull().call(); //succeeds
如果我chekout分支
Git git = Git.open(new File(checkout)); //checkout is the folder with .git
System.out.println(git.getRepository().getFullBranch());
CheckoutCommand checkout = git.checkout();
Ref call = checkout.setName("kalees").call();
它拋出org.eclipse.jgit.api.errors.RefNotFoundException:參考kalees不能解決。
這裏有什麼問題,如果我指定「大師」,而不是「kalees」,它工作正常。我應該做些什麼來結帳一個特定的分支?
如果我使用的代碼
git.checkout().setCreateBranch(true).setName("refs/remotes/origin/kalees");
它檢出kalees分支。但是當我做拉操作
git.pull().call();
它拋出org.eclipse.jgit.api.errors.DetachedHeadException:HEAD是分離。可能是什麼,無論這是結帳問題還是拉問題?
@ kaleeswaran14不知道這是有幫助的。也許'.setForce(true)'在這裏很重要? – VonC
@ kaleeswaran14我編輯了答案以包含更精確的示例。 – VonC
@ kaleeswaran14您可以檢出遠程分支,只要您根據該結帳創建本地分支(否則您處於分離頭模式,這是您的情況)。 – VonC