Undoing Changes Manually in Git
In this article, you will find a quick tip on how to undo changes in Git:
git reset HEAD~n
git push -f origin branch
- Replace "n" with the number of commits to undo, "origin" with the right remote name and "branch" with the right branch name.
- Connect your Git repository, please follow SourceTree instructions for that.
- The following screenshot shows the master and dev branches. Let's assume that the latest commit in the master branch was committed by mistake and you need to revert it:
- By doing right click on the unwanted commit, select Reverse commit:
- This will create a new commit which is the new status. Now, you just need to push the new commit. Use the Push icon in the toolbar and confirm the action:
- Finally, your repository would look similar to this: