使用JGit获取所有分支 [英] Getting all branches with JGit

查看:3686
本文介绍了使用JGit获取所有分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用JGit获取存储库中的所有分支?
让我们来看一个示例库。我们可以看到,它有5个分支。

  int c = 0; 
列表< Ref> call = new Git(repository).branchList()。call(); (Ref ref:call){
System.out.println(Branch:+ ref ++ ref.getName()+
+ ref.getObjectId() .getName());
c ++;
}
System.out.println(分支数量:+ c);

但我得到的只是这个:

<$ $ $ $ b $分行数:1
分行:master
<分行数:$ ref $如果是缺少的远程分支,你必须设置


ListBranchCommand ALL 的code> ListMode > REMOTE 。默认的ListMode( null )仅返回本地分支。

  new Git (repository).branchList()。setListMode(ListMode.ALL).call(); 


How can I get all branches in a repository with JGit? Let's take an example repository. As we can see, it has 5 branches.
Here I found this example:

int c = 0;
List<Ref> call = new Git(repository).branchList().call();
for (Ref ref : call) {
    System.out.println("Branch: " + ref + " " + ref.getName() + " "
            + ref.getObjectId().getName());
    c++;
}
System.out.println("Number of branches: " + c);

But all I get is this:

Branch: Ref[refs/heads/master=d766675da9e6bf72f09f320a92b48fa529ffefdc] refs/heads/master d766675da9e6bf72f09f320a92b48fa529ffefdc
Number of branches: 1
Branch: master

解决方案

If it is the remote branches that you are missing, you have to set the ListMode of the ListBranchCommand to ALL or REMOTE. The default ListMode (null) returns only local branches.

new Git( repository ).branchList().setListMode( ListMode.ALL ).call();

这篇关于使用JGit获取所有分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆