At least one source traced this song back to the 1730s but most references start with a Scottish version of 1827. It has been found all over the English speaking world, especially Scotland.
For another Gloucestershire version, with a tune, see http://glostrad.com/his-old-grey-head-kept-nodding/.
Notes by Gwilym Davies 2 September 2015