SourceTree caught between two branches

Hi,

I have a large mercurial (bitbucket) project, with a default branch and a new branch which is in some form, restructuring the existing site.  This restructure has lead to a number of files being renamed and thus for version tracking we have a series of brand new files and deleted files.  This restructure is still separate to the default branch however earlier today I switched from the new branch to the default to implement a fix and when I attempted to switch back to the new branch I got the following error:

hg update -y -r 1750
abort: crosses branches (merge branches or use --clean to discard changes)

Completed with errors, see above.

 

After cancelling the branch change I had a long list of uncommitted changes on the default branch.  All the files I had renamed in the new branch have now been deleted from the default branch (except those which have had changes made to them since the creation of the new branch) and it's asking me to commit the change.  Those files are now deleted but the "new files" (what I renamed the files to) are not there so it's not a merge.  It feels like the switch got half way complete, deleted the necessary files, errored and returned to the default branch without restoring the deleted files.

Moving to another commit on the default branch does not solve the problem because I still have "uncommitted changes" and the files are still missing.

Should I commit the changes and THEN rollback?  Or discard changes, or "Reset All" (which could mean anything tbh)

Many thanks for your help

 

EDIT:  I can't answer anymore today because I'm new.  

The last commit is definitely on the right branch.

Yes I was switching, not merging and I have not committed the deleted files.

How do I "un-stage" the current changes?


EDIT 2:  So I solved this by selecting each file and using the "discard selected" action.  All files are now restored and everything appears to be working.  Thank you for your time Izhar

5 answers

1 accepted

This widget could not be displayed.

As of now you were just trying to switch back and not merging them, right? So It should not delete any of the files from any branch. If the deleted files are not yet committed to the master branch, you can just un-stage them if not already, then discard/reset those files. This should fix the issue. Alternatively select your latest commit and choose reset "master" to this commit. Being the latest commit selected you will only lose the working copy changes and that is the deletion of those 40 files. After you clean you working directory, try again to switch to the new branch. Thought I have observed in all my past experiences with sourcetree, that it sometimes leaves the extra files in the working directory (which ideally, should be deleted) on switching and later it appears as if we have added some files to our new branch and is pending staging/commit. But it never removed any additional files. It also seems like you *may* have performed a cross branch commit viz. committed to some other branch than the current checked out one. May be your initial switch was not successful but you assumed it so. Make sure of this. Also check whether you have multiple divergent default heads. If this still isn't the case, I am eager to sort this out.

This widget could not be displayed.

Yes working independently on each branch. Always commit latest changes before I switch. I had to implement a small fix on the master this morning, switched over to it, made the changes and committed the changes. When I attempted to switch back to the new branch I got the above error and resulting problem where it had deleted 40 odd files. I'm holding off doing anything for the moment to see what the best solution is. The new branch is scheduled to go live next week, so potentially I could commit the deleted files on the master branch and merge in the new branch now. It wouldn't be ideal but it would not be such a massive inconvenience to merge at this point. Otherwise I could commit the master branch (deleted files) and roll back those changes?

This widget could not be displayed.

Clarification: The new branch has replacement files for those deleted (because they were renamed).

This widget could not be displayed.

As of my understanding of your question, you are working on the two said branches independently, am I right? Also before switching between branches the working copy needs to be in clean state which can be achieved by either commit changes, or discard changes or stash them. If this is not the case, do let me know how the recent changes to your master branch related to/ affects the new branch.

This widget could not be displayed.

So, I see you have solved the issue by discarding the files like I mentioned in my last comment, (somehow 1st comment has moved at the bottom). I have converted the last comment to an answer. Please accept it if you feel like so, So that others could benefit.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
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...

727 views 1 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