Removing/undoing a merge on Sourcetree

This method is based on history deletion:

  1. Check out the branch you made the mistake on
  2. Right click on the commit you want to reset the branch to
  3. Click “Reset current branch to this commit”
  4. Select “Hard” mode and click “OK”
  5. Unfortunately you need terminal to do this bit. Type git push origin name_of_branch --force into terminal (you may need to enter your git repo username and password for it to accept the command)

Update: The current version of source tree supports forced pushes. That means you don’t need to use the command mentioned in step 5! There is a check box visible when pushing that is labled “force”. It is usually disabled.

How to enabled the force push checkbox:

  1. “Tools” (in the blue bar at the top of the screen)
  2. “Options”
  3. “Git” tab
  4. “Enable Force Push” (2nd section)
  5. “OK”

Check that checkbox when pushing to also fix the mistake on the origin server.

This is probably the easiest way to do it but since it is based on history deletion, If others are working on the project, make sure to let them all know what you are doing so you don’t break anyone’s git repository.

Update 2: If you use Visual Studio Code as your code editor, I highly recommend installing the “Git Graph” extension. It allows you to do practically everything that Source Tree allows you to do, but you can do it from directly inside your code editor! The steps for doing this using Git Graph are roughly the same as the steps for doing this in Source Tree.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)