如何在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的很多尝试