michael
michael

Reputation: 110650

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.

Upvotes: 31

Views: 32500

Answers (3)

Yaroslav Yakovlev
Yaroslav Yakovlev

Reputation: 6483

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

Upvotes: 3

Alex Wilson
Alex Wilson

Reputation: 6740

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.

Upvotes: 34

Yuval Adam
Yuval Adam

Reputation: 165340

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

Upvotes: 4

Related Questions