Suppose I've working code in my master branch at PUSH A.
I've pushed some wrong code in my master, say PUSH B
Over my wrong commit, there is one more push. PUSH C
Now I want to revert my code, but keep the correct changes of PUSH C in the master.
Use git revert
command to revert any commit you don't want.
git revert <commit id>
Additionally, if there was a PR raised to merge "PUSH B" then you also get "revert" option in the merged PR, which will ease your work.
Let me know if this helps!