Rotate node to match other node

I have a node (T) to be rotated and a reference node ® which has been rotated. I want to rotate node T to match the rotation of node R. I can reverse rotate node T until the common parent of T and R, then rotate from that parent to node R to get the correct result, but to make it more generalize, the nodes’ position in the tree is not fixed. What is the proper method to rotate in such way?

for moving T to R, I could use
let worldSpacePos = targetNode.convertToWorldSpaceAR(cc.Vec3.ZERO);
let spaceNodePos = spaceNode.convertToNodeSpaceAR(worldSpacePos);
anything similar for rotation?

update:
I see I can get the node’s world matrix by node.getWorldMatrix()
so how can I match node T’s matrix to node R’s matrix?