Good explanation, Carl.
I just want to add that it is probably not a good or safe idea to swim out to the end of the mast to get the boat turned into the wind, ESPECIALLY if you are singlehanding. As Carl said, you can do the same thing by going up on the bow of the boat. If you are at the end of the mast and the boat rights itself, you will be about 30 feet away from the boat and it can easily sail away without you.