According to Sam Henry this is a variant of a song he collected Lady Annie which dates to circa 1815. (The words are very similar to the Digital Tradition version.) Other variants and alternate titles include: Pretty Polly (Like a Trooper Did Ride), Billy Oliver's Rambles, The Maids Resolution to Follow Her Love and Young William.

There is "an old song" using the same tune that is a parody of the Old Pretender (see Jacobite links below):

As Perkin one morning lay musing in bed
The thought of three kingdoms was much in his head...

(Perkin was a nickname used for The Old Pretender in the 1715 Uprising.)

As pretty Polly Oliver
Sat musing, 'tis said,
A comical fancy
Came into her head;
Nor father nor mother
Shall make me false prove,
I'll list for a soldier
And follow my love.

So in soldier's attire
To the wars she went out,
And bore a brave part
In both raid and in rout;
In the battle she found him
Slightly wounded and low
On the ground where he lay
With his face to the foe.

Now Polly he knew
In a moment's quick glance,
And he cried, Why my dear,
Sure I've met you in France;
But the lass she said, nay,
He was surely mistook,
But her words were belied
By the love in her look.

The sergeant sent for
The parson to come,
And couple the lovers
Who'd follow'd the drum;
And Polly, restored to
Her womanly state,
Found all she had sought
In a home and a mate.