I don't think you should be in position to really want automatism for the case. Rebasing even simple branches normally need fair attention. If done on aged branch and/or more than a handful of commits, chances of just succeeding is very small. And you seem to have a full forest there.
While if the situation is not really that fuzzy and rebase mostly work, just issuing an interactive rebase command and cutting the todo manually would take just seconds.
Also from the nature I don't see a full auto solution.
But to be constructive, this is how I would try a solution:
- first create a program that can analyze the source history and gives me tree branches. For the example above it would give B..D on A; E..E on D; F..G on D.
- mark A' as H (from extrenal input)
- Apply the lowest chunk that is based on A: cherry-pick (or rebase onto) B..D to A';
- mark the new top as D'
- apply the remaining chunks for which mapping is already done