In command-line Git, this would be done using git rebase -i ...
and then selecting "fixup" for commits C, D, E, F and G. With fixup, Z would have the same commit message as B.
In JGit, this can be done using RebaseCommand:
InteractiveHandler handler = new InteractiveHandler() {
public void prepareSteps(List<RebaseTodoLine> steps) {
// loop through steps and use setAction to change action
}
public String modifyCommitMessage(String oldMessage) {
return oldMessage;
}
};
Repository repo = FileRepositoryBuilder.create(gitDir);
Git git = Git.wrap(repo);
git.rebase().setUpstream(commitA).runInteractively(handler).call();