SomeKittens
SomeKittens

Reputation: 39522

Merge repos while overwriting changes

I've got a HUGE project. I was assigned to redo the file structure so that it didn't drive our devs insane. It's all in GitHub, so I simply forked the project and made my changes.

I've finished, and now want to pull my changes back in. However, some of our other devs committed to the master repo while I was doing my reorganization. I can't merge, because files were changed that I moved (so Git thinks I deleted them). They are up to date, just in a new location.

How can I successfully pull my reorganized code? My only thought is to delete all the master code from my local repo, and then copypasta the new code to it, and make a commit from there. However, this strikes me as bad practice.

UPDATE: According to this question, git mv would have helped. However, all of the directory changes have already been made.

Upvotes: 2

Views: 162

Answers (1)

dgil
dgil

Reputation: 2358

We had the same problem some days ago.

Here is what we did:

  • merge master branch to new-features branch

    git checkout new-branch
    git merge master
    
  • merge new-features branch to master

    git checkout master
    git merge -s theirs
    

The first merge is to keep all the hotfix applied in the master branch while developing new-features branch. The second merge with strategy option (-s) is to force keep the changes in new-feature branch (we remove and change a lot of code).

You can find more information about merge in this topic When would you use the different git merge strategies?

Upvotes: 2

Related Questions