We investigate the cavity formation during the impact of spheres and cylinders into a liquid pool by using a combination of experiments, simulations and theoretical analysis, with particular interest in contact-line pinning and its relation with the subsequent cavity evolution. The flows are simulated by a Navier–Stokes diffuse-interface solver that allows for moving contact lines. On the basis of agreement on experimentally measured quantities such as the position of the pinned contact line and the interface shape, we investigate flow details that are not accessible experimentally, identify the interface regions in the cavity formation and examine the geometric effects of impact objects. We connect wettability, inertia, geometry of the impact object, interface bending and contact-line position with the contact-line pinning by analysing the force balance at a pinned meniscus, and the result compares favourably with those from simulations and experiments. In addition to adjusting the interface bending, the object geometry also has a significant effect on the magnitude of low pressure in the liquid and the occurrence of flow separation. As a result, it is easier for an object with sharp edges to generate a cavity than a smooth object. A theoretical model based on the Rayleigh–Besant equation is developed to provide a quantitative description of the radial expansion of the cavity after the pinning of the contact line. The accuracy of the solution is greatly affected by the geometrical information on the interface connected to the pinned meniscus, showing the dependence of the global cavity dynamics on the local flows around the pinned contact line. Vertical ripple propagation on the cavity wall is found to follow the dispersion relation for the perturbation evolution on a hollow jet.