In this work, we present results of numerical simulations of the formation and early evolution of rocky planets through pebble accretion, with an emphasis on hydrogen envelope longevity and the composition of the outgassed atmosphere. We modelled planets with a range in mass from 0.1 to 5 Earth masses that orbit between 0.7 and 1.7 AU. The composition of the outgassed atmosphere was calculated with the partial pressure of free oxygen fit to geophysical models of magma ocean self-oxidation. The combined X-ray and UV (XUV) radiation-powered photoevaporation is considered as the main driver of atmospheric escape. We modelled planets that remain below the pebble isolation mass and hence accrete tenuous envelopes only. We considered slow, medium, or fast initial stellar rotation for the temporal evolution of the XUV flux. The loss of the envelope is a key event that allows the magma ocean to crystallise and outgas its bulk volatiles. The atmospheric composition of the majority of our simulated planets is dominated by CO$_2$. Our planets accrete a total of 11.6 Earth oceans of water, the majority of which enters the core. The hydrospheres of planets lighter than the Earth reach several times the mass of the Earth's modern oceans, while the hydrospheres of planets ranging from 1 to 3.5 Earth masses are comparable to those of our planet. However, planets of 4-5 Earth masses have smaller hydrospheres due to the trapping of volatiles in their massive mantles. Overall, our simulations demonstrate that hydrogen envelopes are easily lost from rocky planets and that this envelope loss triggers the most primordial partitioning of volatiles between the solid mantle and the atmosphere.