The story
Ellipsis of hair of the dog that bit one, a folk remedy for rabies by placing hair from the dog that bites one into the wound. The use of the phrase as a metaphor for a hangover treatment dates at least to the 16ᵗʰ century. The principle of “curing like with like” has existed in various cultures historically; see hair of the dog at Wikipedia for details; the use of the phrase “hair of the dog” for a hangover cure dates to antiquity, an early form being found in the Ugaritic text KTU 1.1114 line 29, where the chief god of the pantheon, 'i/el, takes some for his health. The usage is in turn a borrowing from Akkadian.
Etymology from Wiktionary, CC BY-SA 4.0.