git - Same file added by both branches causes weird merge conflict

BrainStone picture BrainStone · Jul 14, 2013 · Viewed 22.8k times · Source

I currently have two branches I am working on. Because of a software update I had to completly change the folder structre. Therefore I moves the files in both branches. Now I reached a point where I want to merge my working branch into my master branch.

The problem is that there are merge conflicts that tell me that a file was added by only one branch (added by them or added by us). The problem is that the file has been added by both branches.

For example I have a texture at textures/texture1.png. The master branch just moved it to the right location (was before misc/textures/texture1.png). The working branch moved it to the exact same location and edited it afterwards. The merge conflict for this file says:

    added by us: textures/texture1.png

The point is that this is not the file I want! I want the file from the other branch!
When I do

git checkout --theirs textures/texture1.png

I get

error: path 'textures/texture1.png' does not have their veresion

But this file does exist! I added it recently! And that's the file I want

How do I resolve these conflicts?

(more information if needed!)

Answer

maximus ツ picture maximus ツ · Jul 14, 2013

You can always try

git mergetool

this will open a GUI, where you can choose your desired changes by just clicking the appropriate links. Sometimes you need to do manual changes. But in your case you just have to select a file image.