For your ear canals, slightly. Over-ear headphones sit outside the ear, so the speaker is farther from your eardrum and nothing goes into the canal. Earbuds can trap moisture and push earwax deeper if you wear them for hours, and dirty tips can irritate the skin.
For your hearing, the type matters less than the volume. An over-ear pair at high volume can damage your hearing just as fast as earbuds. Where over-ears help is that a closed-back pair with good noise cancelling blocks a lot of outside sound, so you can listen at a lower level. Earbuds with a good seal and ANC do the same job. I’d pick whichever pair you’ll wear comfortably and keep at a lower volume.