Imagine the following scenario:
Code that shouldn't have been merged to the integration branch needs to be reverted. However, you can't just reset, since other commits have happened since then. Further, you may want to re-apply that commit at a later time.
It's easy enough to use git revert
to apply a reverse commit. However, what happens when we want to commit that change (from a feature branch, for instance)? Do you just re-merge the branch? Will that work, since technically the code has already been merged?
What do you do when you are finally ready to accept that merge?
You can only reset to a previous commit and ignore the local changes, or revert the changes.
The easiest way to undo the last Git commit is to execute the “git reset” command with the “–soft” option that will preserve changes done to your files. You have to specify the commit to undo which is “HEAD~1” in this case. The last commit will be removed from your Git history.
To undo changes associated with a specific commit, developers should use the git revert command. To undo every change that has happened since a given commit occurred, use git reset.
Just revert the revert commit.
git revert HASH_OF_REVERT_COMMIT
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