The formation of galaxies and the origin of the high-velocity hydrogen