简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM