java - 我如何使用 JGit 进行 pull 或获取?

标签 java git fetch pull jgit

我见过其他类似的问题,但没有看到使用 JGit 获取或 pull 的功能代码。谁能帮我举一个不抛出 JGIT Pull NoHeadException 的小示例或解释。

提前致谢

最佳答案

您可以在 JGit Cookbooks 中查看示例:

即:

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());
        }
    }
}

即:

try (Git git = new Git(repository)) {
    PullResult call = git.pull().call();
    System.out.println("Pulled from the remote repository: " + call);
 }

关于java - 我如何使用 JGit 进行 pull 或获取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22968462/

相关文章:

java - Hibernate继承映射: Table per subclass

git - 如何在 Git 服务器上插入 SSH key (仅限 git-shell 访问)

javascript - 获取数据,函数 Error() { [native code] } <constructor> : "Function"

Git错误: failed to push some refs

excel - VBA for Excel : Server Data Not Updating

fetch - 开 Jest - 类型错误 : Network request failed for fetch

java - 使用C++将类文件转换为jar文件

java - 检查用户是否选择了 fragment 项目

java - 如何从文本文件中读取ArrayList,但每3行一次

.net - 来自 Windows 控制台应用程序的退出代码在 git 钩子(Hook)脚本中不可用