The story
From various expressions such as what the Sam Hill, what the hey, what the heck, what the hell and what the fuck by aposiopesis.
Etymology from Wiktionary, CC BY-SA 4.0.
Today it means: Used to express astonishment or incredulity, as a question or questioning of the situation at hand, without requiring any specific vulgarity as intensifier. Full definition →
From various expressions such as what the Sam Hill, what the hey, what the heck, what the hell and what the fuck by aposiopesis.
Etymology from Wiktionary, CC BY-SA 4.0.