To recover, simply use either a graft
or a replace
which allows you to re-specify the parents of the base(root) of your orphaned branch.
If you do not need to keep your feature branch once it has been merged, then a simple one off graft could be sufficient for you to see the right branching structure.
However the parent linkage at the merge will still keep the orphaned branch and your repo will the have two root commits [probably not what you desire].
The simple improvement is to do a rebase
(of your orphan onto its proper branch point) or a filter-branch
after the graft.
It sounds like you had accidentally checked out the specific commit at the original branch point rather than creating a branch (tip) so that you had a detached HEAD
situation, and did your fix ups in an inappropriate order after some error message - it's easy to do.