WARNING : rewriting history shouldn't be done if branches being rewritten have already been pushed
In other terms, if commit d has already been pushed, you CAN'T do what you want without risking data loss, or generating confusing conflicts.
Okay, so let's assume A has not been pushed.
git rebase is the tool you want.
git checkout A
git rebase -i a
You enter interactive mode (in the configured editor for git), filled in with :
pick sha-of-b message-of-b
pick sha-of-c message-of-c
pick sha-of-d message-of-d
Just insert your cherry-pick at the right place with the x (exec) command :
pick sha-of-b message-of-b
pick sha-of-c message-of-c
exec git cherry-pick sha-of-e # <--- here
pick sha-of-d message-of-d
Git will :
- checkout a
- use b,c as is (at this point, it's exactly as a direct git checkout c)
- cherry-pick e
If there any conflicts, it's time to resolve them normally, then do
git rebase --continue
to integrate commit d
If youd had conflicts cherry-picking e, you'll probably have conflicts again at this time.
Resolve them, and run again
git rebase --continue
to finish rebase.
You can then do a git diff HEAD@{1} to check the difference.