from Brewer's Dictionary of Phrase and Fable

Yankee Doodle is Nankee Doodle (Oliver Cromwell), who went to Oxford “with a single feather fastened in a macaroni knot,” whence the rhyme-

The brigade under Lord Percy marched out of Boston playing this air “by way of contempt,” but were told they should dance to it soon in another spirit.