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.
Git Revert: Reverting the Last Git Commit Make sure to enter the code for the hash you want to revert to. The system asks you to enter a specific commit message for the changes the revert command is going to perform. This action creates a new commit based on the one you specified, with a revert tag.
The long string following the word commit is called the commit hash. It's unique identifier generated by Git. Every commit has one, and I'll show you what they're used for shortly. Note: The “commit hash” is sometimes called a Git commit “reference” or “SHA”.
If you want to revert the last commit, you can use git revert head . head refers to the most recent commit in your branch. The reason you use head~1 when using reset is that you are telling Git to "remove all changes in the commits after" ( reset --hard ) "the commit one before head" ( head~1 ).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With