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 →
8 Replies to “Git – Revert to Specific Commit – Local & Pushed”
Best description of how to do this. Thanks!
This is the best git revert explanation on the webs. Thanks!
Easy and simple to understand, best explanation !!!!!
Great job! Thank you
Simple, and it works – thanks!!
I’m so grateful to see this after 3 hours of browsing.
After git checkout to the commit, the new files added were not deleted. Is there a way to just go back to the state of that particular commit?