Evolutionary dynamics of bacteria in the gut microbiome within and across hosts