Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

reverse merge in Source Tree?

daniel Tipton
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 18, 2012

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

2 votes
Answer accepted
stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 18, 2012

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.

Crystalmyst February 18, 2013

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?

Like Rehanuddin Mohammed likes this
stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 18, 2013
Rehanuddin Mohammed October 4, 2020

Okay

0 votes
Fernando Maia
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 10, 2019

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.

0 votes
daniel Tipton
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 19, 2012

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

0 votes
Ramiro Pointis
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 18, 2012

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events