If this is a shared repository and if there is a chance that anybody has already pulled your commits, then don't try to modify your history. If somebody else has already pulled your commits then you'll be fighting a losing battle to reconcile any additional commits that have been made to your errant branch.
If this is not the case, then you'll want to do some combination of resetting, rebasing and pushing with -f
.
For example, you could reset using git reset --soft <hash>
on the branch in question. This will reset the head of the branch to this commit while leaving all of the subsequent commits unstaged. You could then run git add -p
to selectively restage your changes bit by bit.
Once you're happy with the branch you can then push with git push -f
. This will forcibly overwrite history on the remote - but it cannot remove any history that anybody else might have pulled.