It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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!

4 answers

1 accepted

1 vote
Answer accepted

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?

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).

Guys, I found a way, a bit ugly but does the job.

So, do a hard reset to the commit you want to roll back, go to the project folder (Using Finder on Mac or Explorer on Windows) and make a copy of the whole folder. What you have inside this 'Copy' folder is the point you want to be at the end of this process.

Well... go back to source tree and then checkout the Head (the latest commit into your remote), then navigate again to the project folder, be sure you can see hidden folders because you must be able to see a folder called ".git"

gitsolution.pngDelete everything BUT ".git" from your current project, it means your current project has nothing inside but the folder called ".git", then navigate to your 'Copy' folder and copy everything but ".git" folder and paste the content inside your current project (the one with ".git" folder only)

Done. Go to source tree and commit the changes, your project is exactly where you wanted and all changes removed.

The end.

 

----

Obs1: Delete the "Copy" folder now to clean your pc from dirty files.

Obs2: This process don't remove your changes from Git, the commits will be there, what you are doing is deleting your changes and committing it.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Sourcetree

Sourcetree for Windows - CVE-2019-11582 - Remote Code Execution vulnerability

A vulnerability has been published today in regards to Sourcetree for Windows.  The goal of this article is to give you a summary of information we have gathered from Atlassian Community as a st...

1,669 views 0 10
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you