If I have a branch of single-parent commits; how can I pick a contiguous region of commits from this branch, and add the squash of them to another branch? I do not want to change the original branch (and assume each commit has only one parent).
Here's an example: I want to pick C, D, and E, squash them, and place them onto Z. Then pick F and G, squash them, and place them onto the head of Z. We start with the tree below:
A-----B------C------D------E------F------G------H
 \
  \
   Z
And obtain this result:
A-----B------C------D------E------F------G------H
 \
  \
   Z------Y------X
Where:
Y is the squashed commit of C, D, and E 
X is the squashed commit of F and G. 
I want to avoid the intermediate result below:
A-----B------C------D------E------F------G------H
 \
  \
   Z------C------D------E------F------G
Is there a direct way to do this in JGit? I have been looking at MergeCommand, CherryPickCommand, and RebaseCommand, but I am not sure how to do this while avoiding the intermediate result. I cannot find many JGit examples either. Any suggestions would be helpful. 
 
    