使用JGit获取所有分支 [英] Getting all branches with JGit
问题描述
如何使用JGit获取存储库中的所有分支? 但我得到的只是这个: 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. But all I get is this:
If it is the remote branches that you are missing, you have to set the
这篇关于使用JGit获取所有分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
让我们来看一个示例库。我们可以看到,它有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 $如果是缺少的远程分支,你必须设置
至
ALL
或的code> ListMode
> REMOTE 。默认的ListMode( null
)仅返回本地分支。
new Git (repository).branchList()。setListMode(ListMode.ALL).call();
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);
Branch: Ref[refs/heads/master=d766675da9e6bf72f09f320a92b48fa529ffefdc] refs/heads/master d766675da9e6bf72f09f320a92b48fa529ffefdc
Number of branches: 1
Branch: master
ListMode
of the ListBranchCommand
to ALL
or REMOTE
. The default ListMode (null
) returns only local branches.new Git( repository ).branchList().setListMode( ListMode.ALL ).call();