reverse merge in Source Tree?

I have merged an old copy replacing many files that have been replaced by the older version (my last check out..about a week ago). I am wanting to reset to the previous commit (reverse my damage of merging), is there any way to reverse this merge without losing all the changes since the old checkout? Any help will be appreciated, thanks in advance!

3 answers

1 accepted

This widget could not be displayed.

If you've already committed the merge, then the only way to really undo it is to check out / update to the commit before the merge was done, and proceed from there. You can discard the merge commit using 'strip' in Mercurial and by using 'Reset <branch> to this commit' in Git. Bear in mind that if you've pushed the merge though, you won't want to do that - you'll just have to leave it as an orphaned stream of development unless you're willing to potentially upset other people.

If, you've made commits after the merge that you want to keep, it becomes trickier. You probably want to cherry-pick the commits across to the new branch point in order to do that, but you should expect some potential conflicts.

Revert/Reversing a merge commit has it's advantages. Hence why it's there in Git itself (I'm not sure about hg here).
See: http://git-scm.com/2010/03/02/undoing-merges.html
That directly references reversing the merge commit, which sourcetree does not handle correctly (with the -m flag).

If you have a branch that had a hypothetical 10,000 commits on it, you then merged (badly) into a branch that 20 other people then began working on immediately afterwards.
To cherry-pick each one of those commits is frustrating—and in this exaggerated example will probably take years if done manually—so the simple solution would be to reverse the merge commit, then attempt it again. With git, this is simply done: `git revert -m`.

However attempting this via SourceTree will fail due to it not applying this flag. Thus resulting in having to throw SourceTree aside and boot up a prompt simply to revert a single commit.

Could this be resolved?

This widget could not be displayed.
This widget could not be displayed.

Thasnk you for the quick response. I found this post later after I had already asked. This does answer a portion of the question. It does fall more into the issue mentioned by Steve. I will investigate with this "cherry picking". I am familiar with its purpose, but have never leveraged this tool. I appreciate the help and believe this will solve my issues. I appreciate the elaborating on the question response (I should have traced through the backlog to better define my question so it is unique).

Suggest an answer

Log in or Sign up to answer
Community showcase
Published May 30, 2018 in Sourcetree

Tip from the team: configuring Git or Mercurial in Sourcetree

Supported Platforms macOS Windows To make using Sourcetree as simple yet powerful as possible we embed (bundle) dependencies such as Git, Git LFS, and Mercurial. We strive to keep these...

884 views 2 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you