The center of mass is a geometrical measurement considering only mass distribution and not weight distribution. Centre of mass is a mathematically defined point for an object, which is unaffected by external field/force unless it is deformed by the external field/ force.
However, centre of gravity is a point from where net weight is assumed to act. Clearly it depends on gravity which is an external force.
Normally, centre of mass and gravity are same, this is because Earth’s gravitational field is uniform.
Now, consider a situation in which gravitational field is non-uniform. Also, imagine a very long uniform rod.
If you consider two parts of rod with same mass, the force of gravitation (weight) will be different on both instead of same mass. Due to which, its centre of gravity and center of mass will be different.
Because of this, the position of centre of mass of this rod will be different from that of centre of weight.
Normally, on Earth gravity is uniform so center of mass and gravity are same for most of the objects. But again be cautious!