The phrase Heavens to Betsy is an exclamation expressing surprise or dismay. It is an extended form of the plural noun heavens, which has long been used in exclamations—frequently with an intensifying adjective, as in good heavens and great heavens.
The motivation for the choice of the female forename Betsy (variant of Betty, pet form of Elizabeth) is unknown.
These are the earliest occurrences of the phrase Heavens to Betsy that I have found, in chronological order:
1-: From a short story by Frederick W. Saunders, written for The Flag of our Union (Boston, Massachusetts), titled The Serenade. A Tale of Revenge, and published in that newspaper on Saturday 28th March 1857:
The two conspirators now approach the house with cautious tread, and endeavor to make their way to the rear of the building. The night, as I have before mentioned, is dark, and they do not observe a new Manilla clothes line stretched tightly across the lawn, until Bob, who has his head raised to watch the second story windows, is, as he approaches obliquely, sawed smartly across the neck.
“Heavens to Betsy!” he exclaims, clapping his hand to his throat, “I’ve cut my head off!”
“Not quite, or you wouldn’t yell loud enough to wake the dead,” replied Dick.
2-: From one of the unconnected paragraphs making up the column Readables, published in The Fremont Weekly Journal (Fremont, Ohio) of Friday 22nd July 1870:
Heavens to Betsy, but wasn’t it hot sparking last Sunday night. At least those who tried it said it was.
3-: From Cal Culver and the Devil, by the U.S. author Rose Terry Cooke (1827-1892), published in Harper’s New Monthly Magazine (New York: Harper & Brothers, Publishers) of September 1878:
“Where you goin’?”
“Over to the store,” gloomily answered Cal. “I’m a-goin’ to hire out a spell this year; take it in jobs. Ef I could git a mite o’ cash, I’d go to York, sure as you’re born, and git suthin to do there. Mebbe I’d git onto a whaler.”
“Why, hain’t you got cash enough? I thought she had rents out o’ the housen in Har’ford?”
“Heavens-to-Betsy! You don’t think I ever see a copper o’ her cash, do ye? It’s trusted out to a bank in Har’ford quick as lightnin’.”
4-: From the New Haven Evening Register (New haven, Connecticut) of Friday 12th August 1881:
Scene at the seaside: “Waiter, see here. This check calls for $1.50. I’ve only had three ice creams.”
“That’s correct, sir.”
“Great Scott. Is your ice cream gilt edged that it costs fifty cents a plate.”
“Yes, sir. It comes high, sir, but ice was very scarce last year, sir, and—”
“You villain. There was more ice last year than would make an arctic sea.”
“Yes, sir. Yes, sir. As I was goin’ to say, sir, eggs and cream, sir, is very scarce indeed hereabouts.”
“Eggs aren’t more’n $10 a dozen are they? or milk more’n 37 cents a quart, is it.”
“Yes, sir. I know, sir, it is very high, but you see, sir, there is a great scarcity of customers.”
“Heavens to Betsy, but I should think there would be.”
5-: From Columbia Crum. A Rustic Recitation, by Eugene J. Hall, published in The Daily Inter Ocean (Chicago, Illinois) of Saturday 25th March 1882:
She watched and she waited, while lovers rode by;
She looked and she listened, then said, with a sigh:
“Heavens to Betsy! why can’t nobody come an’ take me a sleigh-ridin’?” (Sighs.)
6-: From one of the unconnected paragraphs making up the column Persons and Things, published in The New Haven Evening Register (New Haven, Connecticut) of Thursday 25th January 1883:
Heavens to Betsy, the Prince of Wales is coming to the United States in March. Now tell us that the Langtry is not a drawing card.
7-: From Hopson’s Choice, by the U.S. author Rose Terry Cooke (1827-1892), published in Harper’s New Monthly Magazine (New York: Harper & Brothers, Publishers) of September 1884—with the spelling Betsey:
“I’m a-goin’ to hev ’Mandy and her feller settle down along with me when they get married. She’ll hev the farm when
‘The end o’ my nose
An’ the tips o’ my toes
Is turned up to the roots of the daisies,’
as the song-book says; and she might as well stop to hum and look after me as to go further and fare worse. But seems to me kinder as if Tertius was slyin’ round Polly, if you’ll b’lieve it.”
“Heavens to Betsey!” gasped Josiah. “That old feller!”
8-: From Ridiculous Randall, published in The Million: A Politico-economic Journal devoted especially to Tariff Reform (Des Moines, Iowa) of Saturday 3rd January 1885:
Mr. Randall has spoken. He has gone to Louisville, the home of the arch enemy, Watterson, and delivered his mission. He has bearded the lion in his den.
The dispatches tell us he was well received. Of course. It was an ovation. We are glad of it. If there is anything we do want, it is that Mr. Randall should get his just deserts and be recognized as the leading and most influential monopoly tariff apostle in the country. No man has so well served the monopolies as he. […]
And what does the great monopolist say, in his infinite wisdom? Heavens to Betsy! He talks in the prattle of the middle ages about the “balance of trade.”
9-: From the Los Angeles Daily Herald (Los Angeles, California) of Thursday 3rd March 1887:
What an Easterner Has to Say of Los Angeles.
The Holyoke, Mass., Transcript has a correspondent who writes in the following pleasant vein about Southern California:
[…] A ride through its grounds [= the grounds of Los Angeles] showed the “drive” bordered with giant palms, beautifully trimmed hedges of cypress plants, graceful festoons of blooming vines, showy specimens of poinsettias, charming pieces of rock-work and ribbon flower-beds, great century-plants, fine specimens of the banana-tree, passion-flowers, heliotropes, geraniums, callas, trumpet-vines, English ivies, roses, yuccas, etc., etc., in profusion. No wonder that feminine tongues exhausted all common epithets of praise and resorted to “Glory to Gideon” and “Heavens to Betsy” in their ejaculations of admiration.