Undoing Changes Manually in Git

Updated 1 year ago by Copado Solutions

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

  1. Replace "n" with the number of commits to undo, "origin" with the right remote name and "branch" with the right branch name.
If Git command line is not an alternative, you can achieve the same using a GUI such as SourceTree
  1. Connect your Git repository, please follow SourceTree instructions for that.
  2. 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:

  1. By doing right click on the unwanted commit, select Reverse commit:

  1. 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:

  1. Finally, your repository would look similar to this:

How did we do?