我看到过其他类似的问题,但没有看到使用JGit获取或提取的函数代码。有人能帮我举一个不引发JGIT Pull NoHeadException的小例子或解释吗。
提前感谢
您可以在JGit Cookbooks:中看到示例
FetchRemoteCommits.java
即:
public static void main(String[] args) throws IOException, GitAPIException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
System.out.println("Starting fetch");
try (Git git = new Git(repository)) {
FetchResult result = git.fetch().setCheckFetchedObjects(true).call();
System.out.println("Messages: " + result.getMessages());
}
}
}
PullRemoteRepository.java
即:
try (Git git = new Git(repository)) {
PullResult call = git.pull().call();
System.out.println("Pulled from the remote repository: " + call);
}