Just like giraffes, the reason they had their long neck was to reach the foliage of tall trees. They’ve lived in a place full of things taller than them.
Pretty sure some or most of the sauropods had long necks to sweep areas without needing to love their bodies as far for each bite, similar to swans and geese and other long necked birds. Some likely did it for height, like the Brachiosaurus, but their body structure is more upright like a giraffe. Diplodicus and others were more horizontal.