POE: Phrases of Excitement.
An utterance of great surprise, an exclamation of joy, awe, or fright.
An exclamation - a euphemistic shortening of God's hooks (the nails on the cross).
As the meaning suggests, this was originally two words - gad's zooks, which was sometimes hyphenated and now almost always spelled as a single word.
Gad was a common term used to avoid speaking the name of God - an example of a minced oath. That taboo, although still influential amongst the devout, is now much weaker and the use of gad has diminished as a consequence. In the 17th century we would have had a choice of such 'gad' words - gadsbobs, gadsbodikins, gadsbud, gadsbudlikins,gadsokers, gadsookers, gadsprecious, gadswookers, gadswoons - gad pretty much anything you like. These share a format with many reduplications - many of which also take an existing word and add a secondary made-up word for emphasis. Gad began life in the early 17th century.