Don’t make it complicated.
First you need to do a git log to find out which commit ID you want to revert. For example it is commit abc123. If you know that it’s the last one, you can use a special identifier “HEAD”.
Then you first revert it locally in your local “staging” branch:
git checkout staging
git revert abc123
Note: for the last commit in the log you would write git revert HEAD.
And then you update your remote “staging”:
git push
Explanation: In git if you have a remote you are dealing with 2 distinct repositories (local and remote). After you do git checkout staging, you actually create a distinct local name that represents the remote branch. git revert actually doesn’t delete your commit, but it creates a new commit on top, that undoes all the changes (if you added a file – the new commit will remove it, if you removed a line – the new commit will add it back etc.), i.e. it is an addition to the log, that’s why the push will be clean.
If you want to really make it gone, so that nobody can blame you, you can do at your risk:
git checkout staging
git reset --hard HEAD^
git push -f
(the reset line retargets the local “staging” branch so that it points to a commit that is right before your top commit)
In general the forced push is a bad practice, but keeping useless commits and reverts around is not nice as well, so another solution would be to actually create a new branch “staging2” and do your testing in that branch instead:
git checkout staging
git checkout -b staging2
git reset --hard HEAD^
git push