簡體   English   中英

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

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

我見過其他類似的問題,但沒有看到使用JGit獲取或拉取的功能代碼。 任何人都可以通過一個不會引發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);
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM