Skip to content

[Step 6] Undo a commit locally (Reset)

Sam Lin edited this page Jan 18, 2018 · 2 revisions

ref

After step 5, let's say the merge commit was a mistake. We want to undo it.

  1. Go to Synchronization tab, click Actions > View History

  2. It brings up a History tab

  3. In the checkout branch, right-click on the commit before the merge commit we just did in step 5 to bring up the context menu.

  4. Hover over Reset and you can either

    • Keep Changes, which means the commit will be removed but the change is still there in your workplace
    • Delete Changes, which means the commit and changes will be removed.

    Need more info? ref

    Let's try keep changes and re-commit and try Delete changes.

  5. Click Keep Changes, and click Refresh in the history tab. Review the new branch graph

  6. In Team Explorer, go to Changes tab, there should be changes, which is the merge changes we made before.

  7. If we commit it again now, it will just be a normal commit instead of merge commit. Enter commit message and click Commit All. It will look like this.

  8. In History tab, right-click on the previous commit, and click Reset > Delete Changes. This will undo the last commit and discard the changes in the workplace. It will be like this after refresh.

The whole process

Do it in SourceTree

Related Commands:

  • git reset --hard "HEAD^"
  • git reset --soft "HEAD^"
  • git reset --hard ORIG_HEAD
  • git commit --amend
Clone this wiki locally