The shock-induced transition from graphite to diamond has been of great scientific and technological interest since the discovery of microscopic diamonds in remnants of explosively driven graphite. Furthermore, shock synthesis of diamond and lonsdaleite, a speculative hexagonal carbon polymorph with unique hardness, is expected to happen during violent meteor impacts. Here, we show unprecedented in situ X-ray diffraction measurements of diamond formation on nanosecond timescales by shock compression of pyrolytic as well as polycrystalline graphite to pressures from 19 GPa up to 228 GPa. While we observe the transition to diamond starting at 50 GPa for both pyrolytic and polycrystalline graphite, we also record the direct formation of lonsdaleite above 170 GPa for pyrolytic samples only. Our experiment provides new insights into the processes of the shock-induced transition from graphite to diamond and uniquely resolves the dynamics that explain the main natural occurrence of the lonsdaleite crystal structure being close to meteor impact sites.