The derivation may
be the association that wood and trees have with good spirits in mythology, or
with the Christian cross. It used to be considered good luck to tap trees to let the wood spirits within know you were there. Traditions of this sort still persist in Ireland. See also – the darling buds of May.
The British version of the phrase – ‘touch wood’, pre-dates the American ‘knock on wood’ and was itself preceded by a Latin version – ‘absit omen’, meaning ‘far be that omen from us’. This dates from at least the early 17th century, when it is quoted by John Heywood in his A Dialogue conteinyng the nomber in effect of all the Prouerbes in the Englishe tongue. It isn’t clear when ‘touch wood’ began to be used as a token of good fortune but it must have been by 1850, when the academic correspondence magazine Notes and Queries published this:
There probably is some old English expression for averting evil, but it does not come to mind; “I touch wood,” “Bar omen,” “Bar ill-luck,” seem clumsy.
‘Knock on wood’ is known from the early 20th century; for example, The Syracuse Herald, February 1905:
Neglecting to knock on wood may have been responsible for the weather’s unseemly behaviour today.