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

Merging from branch deletes files added to master

Anthony Hughes Jun 18, 2015

New to SourceTree and GIT branching...

We have a git repro where all the main development happens along the master trunk, but some time ago a separate branch was created for some experimental work. I'm now trying to merge that branch back into master with SourceTree but having a major problem where all the files that have been added to master since the other branch was created (and don't exist in that branch) are being flagged as deleted from master.

Here's what I'm doing

  • Make sure master is checked out
  • Select the latest commit on master
  • Click Merge
  • Select the most recent commit of the other branch
  • Click OK

The result is a bunch of conflicts as expected, but also a mass of "deleted" files that really should not be!

What's going on??

Thanks 

2 answers

0 votes
sreekumar menon Jun 18, 2015

what you need to do is a simple merge from your branch to master. no need to select a commit.

This is what I do.

checkout master branch in sourcetree.

right click on your other branch (on left tree) and select "merge branch into current branch" .  current branch is master .

and it should merge all changes from other to master.

Anthony Hughes Jun 22, 2015

Thanks for the tip - unfortunately this give me exactly the same result as before sad

Anthony Hughes Jun 22, 2015

Ok I've found out a bit more - there was a merge of the master into the branch at one point in the past, but shortly after that a revert to a commit before the merge (don't ask me why). Selecting this revert shows all the files that we new in the master as to be deleted in the branch.

Any attempt to merge the branch into master after this point causes the master files to be deleted.

How do I get out of this mess?

sreekumar menon Jun 22, 2015

so you are saying there is a commit that reverts the newly added files ,which is removing the newly added files.

you could revert that commit again*(commit that is reverting ),which will put all the files back. 

 

Anthony Hughes Jun 22, 2015

There was a commit (some changes) then a merge with master, then the commit was reverted, which also removed all of the files added by the merge because it happened after the commit that was being reverted. As well as removing new files, this revert also undoes the changes in master that had happened up to the point of the revert.

0 votes
Peter Schueffler Feb 16, 2019

I think you can avoid that issue by following practice:

before you merge the branch into the master, you go to your branch and pull from the master (applying the latest changes, new files etc). Then you resolve conflicts on your branch, then you merge to the master. 

Even if your branch has a wired past, it will then know what the master should be and just apply the current differences, instead of wired past differences. 

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Sourcetree

[dev team] Sourcetree for Windows 2019 Preview - Dark Theme

Hi folks, While the full post is over on our blog I'd like to share the dark theme we've got planned for 2019 here directly as well to keep the discussion going.  The ...

1,952 views 14 18
Join discussion

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