列出一个git远程仓库的分支而不克隆它 [英] List branches of a git remote repo without cloning it

查看:423
本文介绍了列出一个git远程仓库的分支而不克隆它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道怎么可能用jgit列出远程Git仓库的所有分支但没有克隆它。

I was wondering hows it would be possible to list all the branches of a remote Git repo with jgit but without cloning it.

在浏览jgit的javadoc时,我找到了 ListBranchCommand ,但这似乎只能起作用使用已打开的Repository对象。但我无法找到如何通过HTTP创建Repository对象而无需在本地克隆它。

While going through the jgit's javadoc, I found the ListBranchCommand but that only seem to work with an already opened Repository object. But I was not able to find how to create a Repository object over HTTP without cloning it in local.

有可能吗?
谢谢

Is it possible ? Thanks

推荐答案

LsRemoteCommand 列出远程存储库的分支。要获得该命令,请使用

There is the LsRemoteCommand to list the branches of a remote repository. To obtain the command, use either

Git.wrap( repo ).lsRemote()

Git.lsRemoteRepository()

静态创建的 LsRemoteCommand 有其局限性。对于某些传输协议,需要本地存储库来获取配置设置。因此,我通常使用 Git.init()创建一个空的临时本地存储库,然后使用第一种方法。

The statically created LsRemoteCommand has its limitations. For certain transport protocols, a local repository is necessary to obtain configuration settings. Therefore I usually create an empty temporary local repository with Git.init() and then use the first approach.

如果要避免创建额外的存储库,可以使用 Transport.open()进行测试,如果它没有存储库则成功。否则抛出 NotSupportedException

If you want to avoid creating the extra repository, you can test with Transport.open() if it succeeds without a repository. It throws a NotSupportedException otherwise.

这篇关于列出一个git远程仓库的分支而不克隆它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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