Search code examples
gitgit-revert

How to git revert a commit using a SHA


How can I revert a commit with a GIVEN SHA? I just want to remove the changes with a given SHA? I want to keep all the commits made BEFORE & AFTER the give SHA. I just want to remove changes of that specified SHA.

I have read Revert to a commit by a SHA hash in Git?, my understanding is that reset all the commits made AFTER the SHA i want to revert. That is not way i want.


Solution

  • 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.