This is an old topic, but I just ran across it while looking for similar information.
A trick similar to the one described in Subtree octopus merge is a really good solution to this type of problem:
git checkout my-feature
git reset --soft Y
git rev-parse f > .git/MERGE_HEAD
git commit
That will take the index as it exists at the tip of my-feature, and use it to create a new commit off of Y, with ‘f’ as a second parent. The result is the same as if you’d never performed M1, but gone straight to performing M2.