I don't think that this is possible to do in Git, by design.
A commit ID is based on older commits, so if your old commits change, then your newer ones should change as well.
In any case, I'm assuming you've already pushed this history to a remote, since you want to keep the top commit ID the same, and that you shouldn't be doing; it'll mess up other people's repos.
On the other hand, if you haven't pushed, then simply do a squash.
...one of the most widely used is the ability to squash commits. What
this does is take smaller commits and combine them into larger ones,
which could be useful if you’re wrapping up the day’s work or if you
just want to package your changes differently.
A word of caution: Only do this on commits that haven’t been pushed an
external repository. If others have based work off of the commits that
you’re going to delete, plenty of conflicts can occur. Just don’t
rewrite your history if it’s been shared with others.