How did James Cook damage his ship?

As Captain Cook sailed north along the Queensland coast, his ship the "Endeavour" struck the Great Barrier Reef and nearly sank. The Endeavour managed to stay afloat for another week whilst the crew sought desperately for land, eventually sighting the harbour formed by the Endeavour River. The ship was landed on 10 June 1770, and Cook spent almost two months repairing it, thus giving rise to the fledgling township of Cooktown.