[英]JGit branch checkout Issue
我正在使用以下代碼從github檢出存儲庫。
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。
這里有什么問題,如果我指定“master”而不是“kalees” , 它可以正常工作 。 我應該做什么改變來結賬一個特定的分支?
如果我使用代碼
git.checkout().setCreateBranch(true).setName("refs/remotes/origin/kalees");
它結帳了kalees分支。 但是當我拉動操作時
git.pull().call();
它拋出org.eclipse.jgit.api.errors.DetachedHeadException:HEAD被分離 。 可能是什么,這是一個結賬問題還是拉動問題?
它應該只發生在:
kalees
不是現有的分支(或kalees
了,壞的情況) kalees
是一個遠程分支,你已經跟蹤了一個本地分支 如果是這樣,您可能需要先創建它(有點像這個例子 )
git.branchCreate().setForce(true).setName("kalees").setStartPoint("origin/kalees").call();
在“ JGit:無法找到教程或簡單示例 ”之后,我寧願使用:
git.branchCreate()
.setName("kalees")
.setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM)
.setStartPoint("origin/kalees")
.setForce(true)
.call();
當我想創建一個具有空存儲庫的分支時,我遇到了這個問題,此存儲庫中沒有提交。
當我向存儲庫提交內容時,它已得到解決。 希望它對你有幫助:)
Muthu你的代碼工作你只需要將這樣的origin / branch添加到分支調用
Ref call = checkout.setName("origin/kalees").call();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.