final Git repoAgit = Git.cloneRepository()
            .setURI(repoAgitUrl)
            .setDirectory(new File(repoApath))
            .setBranchesToClone(Arrays.asList("refs/heads/develop"))
            .setBranch("refs/heads/develop")
            .setTransportConfigCallback(TRANSPORT_CONFIG_CALLBACK)
            .call();
final Git repoBgit = Git.cloneRepository()
            .setURI(repoBgitUrl)
            .setDirectory(new File(repoBpath))
            .setBranchesToClone(Arrays.asList("refs/heads/develop"))
            .setBranch("refs/heads/develop")
            .setTransportConfigCallback(TRANSPORT_CONFIG_CALLBACK)
            .call();


如何将repoA合并到repoB,其中repoA应该在repoB之前,而repoBrepoA的分叉版本?

最佳答案

首先,在repoB中,创建引用repoA的遥控器。

然后从此远程获取,以便有两个本地分支:refs/heads/developrefs/remotes/repoa/develop

如果尚未完成,请在repoB中签出目标分支refs/heads/develop

调用MergeCommand将远程跟踪分支合并到HEAD。

例如:

repoB.remoteAdd().setName("repoa").setUri(new URIish("/path/to/repoA")).call();
repoB.fetch().setRemote("repoa").call();
MergeResult mergeResult = repoB.merge()
    .include(repoB.getRepository().resolve("refs/remotes/repoa/develop"))
    .call();

09-03 23:48