Assuming you have a bearing angle for each object relative to its parent, this is just subtraction.
parent_angle + child_angle = target_angle
parent_angle = target_angle - child_angle
So in your example, the child is rotated about 45 degrees clockwise from its parent - call that -45 - and the target is unrotated at 0 degrees, so that gives:
parent_angle = 0 - (-45)
So the parent needs to be rotated 45 degrees counter-clockwise to compensate for the child's rotation and match it to the target.
This expression can wrap around to values outside the -180 to 180 or 0 to 360 or -pi to pi etc. range you might be using, but you can wrap the result with an angle difference function, if that matters for your use case. Prior Q&A covers how to write such a function, if your math library does not offer one built-in.