【发布时间】:2012-09-27 05:26:37
【问题描述】:
我正在使用以下代码从 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
如果我结账一个分支
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: Ref kalees can't be resolve.
这里有什么问题,如果我指定 "master" 而不是 "kalees",它可以正常工作。我应该做些什么来结帐特定的分支?
如果我使用代码
git.checkout().setCreateBranch(true).setName("refs/remotes/origin/kalees");
它检查了 kalees 分支。但是当我做拉操作
git.pull().call();
它抛出 org.eclipse.jgit.api.errors.DetachedHeadException: HEAD is detached。可能是什么,这是结帐问题还是拉取问题?
【问题讨论】: