Aims. We study the star formation fistory (SFH) of 210 galaxy members of 55 Hickson compact groups (HCG) and 309 galaxies from the Catalog of Isolated Galaxies (CIG). The SFH traces the variation of star formation over the lifetime of a galaxy, and consequently yields a snapshot picture of its formation. Comparing the SFHs in these extremes in galaxy density allows us to determine the main effects of compact groups (CG) on the formation of galaxies. Methods. We fit our spectra using the spectral synthesis code STARLIGHT and obtained the stellar population contents and mean stellar ages of HCG and CIG galaxies in three different morphological classes: early-type galaxies (EtG), early-type spirals (EtS), and late-type spirals (LtS). Results. We find that EtG and EtS galaxies in HCG show higher contents of old and intermediate stellar populations as well as an important deficit of the young stellar population, which clearly implies an older average stellar age in early galaxies in HCG. For LtS galaxies we find similar mean values for the stellar content and age in the two samples. However, we note that LtS can be split into two subclasses, namely old and young LtS. In HCG we find a higher fraction of young LtS than in the CIG sample, in addition, most of these galaxies belong to groups in which most of the galaxies are also young and actively forming stars. The specific star formation rate (SSFR) of spiral galaxies in the two samples differ. The EtS in HCG show lower SSFR values, while LtS peak at higher values compared with their counterparts in isolation. We also measured the shorter star formation time scale (SFTS) in HCG galaxies, which indicates that they have a shorter star formation activity than CIG galaxies. We take these observations as evidence that galaxies in CG have evolved more rapidly than galaxies in isolation, regardless of their morphology. Our observations are consistent with the hierarchical galaxy formation model, which states that CGs are structures that formed recently from primordial small-mass density fluctuations. From the systematic difference in SFTS we deduce that the HCG have most probably formed ∼3 Gyr in the past. The galaxies in the HCG are not in equilibrium state, but merging without gas (i.e., under dissipationless conditions), which may explain their relatively long lifetime.