加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 如何在JGit中合并?

发布时间:2020-12-14 05:48:06 所属栏目:Java 来源:网络整理
导读:如何在J Git中合并? 假设我想把大师与foo分支合并,怎么办? 解决方法 要合并,可以在CheckoutCommand之后使用MergeCommand(在包org.eclipse.jgit.api中).为您提供一个例子,因为确实Jgit缺少例子: Git git = ... // you get it through a CloneCommand,InitC
如何在J Git中合并?

假设我想把大师与foo分支合并,怎么办?

解决方法

要合并,可以在CheckoutCommand之后使用MergeCommand(在包org.eclipse.jgit.api中).为您提供一个例子,因为确实Jgit缺少例子:
Git git = ... // you get it through a CloneCommand,InitCommand 
              // or through the file system

CheckoutCommand coCmd = git.checkout(); 
// Commands are part of the api module,which include git-like calls
coCmd.setName("master");
coCmd.setCreateBranch(false); // probably not needed,just to make sure
coCmd.call(); // switch to "master" branch

MergeCommand mgCmd = git.merge();
mgCmd.include("foo"); // "foo" is considered as a Ref to a branch
MergeResult res = mgCmd.call(); // actually do the merge

if (res.getMergeStatus().equals(MergeResult.MergeStatus.CONFLICTING)){
   System.out.println(res.getConflicts().toString());
   // inform the user he has to handle the conflicts
}

我没有尝试代码,所以它可能不完美,但只是提供一个开始.而且我没有包括进口.用JGit开发意味着基于javadoc的很多尝试

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读