For starters, as @RomainVALERI pointed out, I'd be really careful resetting history on a remote branch that is shared with others. For instance, if it's a dev or master branch, it's never a good idea to reset history in any way.
There are two common ways to undo a commit in git.
1. Revert the bad commit (no history alteration)
This is the safest route to go for shared branches like dev, master, etc. since someone might have already pulled in the bad commit you made. You just create a new commit that undoes the bad commit and push.
git revert <commit_hash>
git push
Since your question tells me that it's the most recent commit (the one HEAD
is pointing to), you can also do git revert HEAD
and push.
2. Reset old commit and force push (rewrite history)
You can take this route if it's a branch that you're working with. It might be a feature or bugfix branch. Since it's just you working on it, rewriting history won't matter much.
Again, I'll assume here that it's the most recent commit that you want removed. There are more involved ways to deal with an older commit (see: git rebase)
As @Rohan put in his answer, just reset your HEAD
to the commit before the bad commit and force push.
git reset HEAD
git push --force
Update 1-
Hosting providers (viz. VSTS, GitHub) also allow admins to put branch policies that everyone needs to adhere to. A very common policy for dev/master branches is to disable "force push" for the very reason I mentioned above. If it's a shared repo, there's a good chance that you might not have "force push" privileges and you'll have to take the "revert" route.