Evolution appears a sensible explanation for the adaption of creatures, if it works you have an advantage and get to reproduce and the mutation is passed on.
I have wondered tho’ if wishful thinking might play a part, that a collective mind might think, “It would be really great if I had a long neck to reach those tasty leaves up there”
and so the giraffes DNA is changed by will power so that the off-spring has longer necks.
What the mechanism might be I have no idea.
I heard an assertion but have no source that a bacteria changed its metabolism in its own lifetime to adapt to new circumstances when it was really stressed.
I like Life being a mystery.