We study the evolution of the cold gas content of galaxies by splitting the interstellar medium into its atomic and molecular hydrogen components, using the galaxy formation model GALFORM in the LCDM framework. We calculate the molecular-to-atomic hydrogen mass ratio, H2/HI, in each galaxy using two different approaches; the pressure-based empirical relation of Blitz & Rosolowsky and the theoretical model of Krumholz, McKeee & Tumlinson, and apply them to consistently calculate the star formation rates of galaxies. We find that the model based on the Blitz & Rosolowsky law predicts an HI mass function, CO(1-0) luminosity function, correlations between the H2/HI ratio and stellar and cold gas mass, and infrared-CO luminosity relation in good agreement with local and high redshift observations. The HI mass function evolves weakly with redshift, with the number density of high mass galaxies decreasing with increasing redshift. In the case of the H2 mass function, the number density of massive galaxies increases strongly from z=0 to z=2, followed by weak evolution up to z=4. We also find that the H2/HI ratio of galaxies is strongly dependent on stellar and cold gas mass, and also on redshift. The slopes of the correlations between H2/HI and stellar and cold gas mass hardly evolve, but the normalisation increases by up to two orders of magnitude from z=0-8. The strong evolution in the H2 mass function and the H2/HI ratio is primarily due to the evolution in the sizes of galaxies and secondarily, in the gas fractions. The predicted cosmic density evolution of HI agrees with the observed evolution inferred from DLAs, and is dominated by low/intermediate mass halos. We find that previous theoretical studies have largely overestimated the redshift evolution of the global H2/HI ratio due to limited resolution. We predict a maximum of rho_H2/rho_HI~1.2 at z~3.5.