Cosmic galaxy assembly and the evolution of metals