Simplification of @Daira Hopwood method good for picking one single commit. Need no temporary branches.
In the case of the author:
then do:
git checkout Z # move HEAD to wanted commit
git reset Y # have Z as changes in working tree
git stash # save Z in stash
git checkout X # return to working branch
git stash pop # apply Z to current branch
git commit -a # do commit