简体   繁体   English

列出一个git远程仓库的分支而不克隆它

[英]List branches of a git remote repo without cloning it

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列出远程Git仓库的所有分支但没有克隆它。

While going through the jgit's javadoc, I found the ListBranchCommand but that only seem to work with an already opened Repository object. 在浏览jgit的javadoc时,我发现了ListBranchCommand,但它似乎只适用于已经打开的Repository对象。 But I was not able to find how to create a Repository object over HTTP without cloning it in local. 但我无法找到如何通过HTTP创建Repository对象而不在本地克隆它。

Is it possible ? 可能吗 ? Thanks 谢谢

There is the LsRemoteCommand to list the branches of a remote repository. LsRemoteCommand用于列出远程存储库的分支。 To obtain the command, use either 要获取该命令,请使用其中一个

Git.wrap( repo ).lsRemote()

or 要么

Git.lsRemoteRepository()

The statically created LsRemoteCommand has its limitations. 静态创建的LsRemoteCommand有其局限性。 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. 因此,我通常使用Git.init()创建一个空的临时本地存储库,然后使用第一种方法。

If you want to avoid creating the extra repository, you can test with Transport.open() if it succeeds without a repository. 如果要避免创建额外的存储库,可以使用Transport.open()进行测试,如果它没有存储库则成功。 It throws a NotSupportedException otherwise. 否则会抛出NotSupportedException

Ok, never mind, after hours searching for the answer, I find it right before asking it there... 好吧,没关系,经过几个小时寻找答案后,我发现它就在那里问它之前......

So, the answer is in the CookBook : 所以,答案在CookBook中

Collection<Ref> refs = Git.lsRemoteRepository()
            .setHeads(true)
            .setTags(true)
            .setRemote(REMOTE_URL)
            .call();

暂无
暂无

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

相关问题 将文件从 web 应用程序(弹簧启动)提交到 git 远程存储库,而不首先将存储库克隆为本地? 这可能吗 - commit file from a web application (spring boot) into git remote repository without first cloning the repo as local? is this possible 如何从 GIT Repo 读取文件数据。 无需使用 JGIT API 在本地克隆它 - How to read the file data from GIT Repo. without cloning it in local using JGIT API 连接和克隆远程git仓库之间的区别 - Difference between connecting and cloning remote git repository 是否有任何 Jgit API 可以通过它从 GIT repo 上的特定文件中读取内容。 无需克隆其中的所有数据 - Is there any Jgit API by which we can read contents from particular file on GIT repo. without cloning all the data inside it 在远程Git仓库中导出Java和Spring项目 - Exporting java and spring project in a remote git repo 使用JGit检索远程Gerrit提交日志,而不克隆存储库? - Retrieve remote Gerrit commit logs using JGit without cloning the repository? 在没有 Git 存储库的情况下使用 Spring Cloud Config - Using Spring Cloud Config without Git repo 如何将Java Project从IntelliJ IDEA保存到Git repo,以便在克隆后在另一台PC上构建? - How to save Java Project from IntelliJ IDEA to Git repo so it will build on another PC after cloning? Git:如何在不丢失当前分支的情况下克隆项目? - Git: How to clone project without losing the current branches? 如何在不克隆本地存储库的情况下获取提交列表 - How to get the list of commits without cloning the repository in local
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM