If you just want to "discard" the commit you can use the revert
command.
git revert
git revert <sha>
will add a new commit which will revert (undo) the given commit. The revert will create a new commit which will generate a path opposite the given commit so you will have the original code in the first commit and the removal of this code in the new commit
git reset
In case the commit(s) you wish to discard are on the top of your branch and you have permission to force push
than you can use reset. The limitations here are that you can force push and that there is no other commit in between the reset range that you wish to keep.
git revert
= Undo the given commit and add new commit of the undo
git reset
= Move the HEAD
of the branch to the desired point by "cutting" off the commits from the branch