如何在JGit中合并?

如何在JGit中合并?

假设我要masterfoo分支合并,该怎么做?

回答:

要合并,您可以MergeCommand在之后使用(在org.eclipse.jgit.api包中)CheckoutCommand。为了给您提供示例,因为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的许多尝试

以上是 如何在JGit中合并? 的全部内容, 来源链接: utcz.com/qa/415115.html

回到顶部