  The close relationship between mergers and the reorientation of the spin for
galaxies and their host dark haloes is investigated using a cosmological
hydrodynamical simulation (Horizon-AGN). Through a statistical analysis of
merger trees, we show that spin swings are mainly driven by mergers along the
filamentary structure of the cosmic web, and that these events account for the
preferred perpendicular orientation of massive galaxies with respect to their
nearest filament. By contrast, low-mass galaxies (M_s<10^10 M_sun at redshift
1.5) undergoing very few mergers, if at all, tend to possess a spin well
aligned with their filament. Haloes follow the same trend as galaxies but
display a greater sensitivity to smooth anisotropic accretion. The relative
effect of mergers on spin magnitude is qualitatively different for minor and
major mergers: mergers (and diffuse accretion) generally increase the magnitude
of the angular momentum, but the most massive major mergers also give rise to a
population of objects with less spin left. Without mergers secular accretion
builds up the spin of galaxies but not that of haloes. It also (re)aligns
galaxies with their filament.
