Java – how to merge in jgit?
                                        
                    •
                    Java                                    
                How do I merge in J git?
Suppose I want to merge master with foo branch, what should I do?
Solution
To merge, you can use mergecommand after checkoutcommand (in the package org. Eclipse. Jgit. API) An example is provided for you, because jgit really lacks an example:
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
}
I didn't try the code, so it may not be perfect, but it just provides a start And I don't include imports Developing with jgit means a lot of attempts based on Javadoc
                            The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
                        
                                            
                        THE END
                    
                    
                    
                                                        二维码
                        
                        
                                                
                        