In Git we can gracefully revert all changes to the specific commit without using the potentially dangerous
git reset command.
In this note i am showing how to undo local changes by making a rollback to the specific commit and how to revert a commit that has already been pushed to remote.
Cool Tip: Revert a file to the previous commit! Read more →
Git – Revert to Specific Commit
Find the specific commit you want to revert all changes to:
$ git log --oneline
Rollback all changes to that old commit:
$ git checkout be9055b .
Note: The dot (
.) after the branch name is mandatory.
Add the changes to the staging area and commit them:
$ git add -A $ git commit -m "Revert commit: be9055b"
Once the local rollback is done, you can revert the already pushed commits, by pushing a new revision with the reverted changes to the remote Git repository:
$ git push
Cool Tip: Clear Git history by removing all commits! Read more →