Second-order nonlinear optical response allows to detect different properties of the system associated with the inversion symmetry breaking. Here, we use a second harmonic generation effect to investigate the alignment of a graphene/hexagonal Boron Nitride heterostructure. To achieve that, we activate a commensurate-incommensurate phase transition by a thermal annealing of the sample. We find that this structural change in the system can be directly observed through a strong modification of a nonlinear optical signal. This result reveals the potential of a second harmonic generation technique for probing structural properties of layered systems.