简体   繁体   English

如何使用JGit进行拉取或取出?

[英]How do I use JGit for Pulling or Fetching?

I had seen other similar questions but not a functional code that fetchs or pulls using JGit. 我见过其他类似的问题,但没有看到使用JGit获取或拉取的功能代码。 Could anyone help me with a small pulling example or explanation that doesn't throws a JGIT Pull NoHeadException. 任何人都可以通过一个不会引发JGIT Pull NoHeadException的小拉动示例或解释来帮助我。

Thanks in advance 提前致谢

You can see examples in JGit Cookbooks: 您可以在JGit Cookbooks中看到示例:

That is: 那是:

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

That is: 那是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM