How to git revert a commit using a SHA
You can use git revert <commit hash>
to try to revert the changes made by the commit. This will not remove the commit from history, just make changes to undo it as a new commit. In other words you will have the first commit still in history, and an additional commit on the head of your branch which is the effective inverse of the original commit.
If you have not yet shared your changes with anyone else, then it is possible to remove the original offending commit from history altogether by using git rebase
. There are details in this SO post.
git revert <commit>
will attempt to revert a single commit.
It will not change any other commits. You might be confused by git reset
which does something entirely different.
For more info: https://www.kernel.org/pub/software/scm/git/docs/git-revert.html
One can use the
git revert <commit hash> --no-commit
if they want to tweak the changes produced by commit revert, before they commit again. For more information have a look here