To not rewrite history, you can use git revert .
This will create a new commit, which is the inverse of the command that you accidentally pressed.
Find the bunch of commits you pressed and run this command for each step:
git revert <sha>
Then move the return commit.
source
share