Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 767
BrainStone Avatar asked Jul 14 '13 13:07

BrainStone


People also ask

Why do I keep getting merge conflicts?

Often, merge conflicts happen when people make different changes to the same line of the same file, or when one person edits a file and another person deletes the same file. You must resolve all merge conflicts before you can merge a pull request on GitHub.


1 Answers

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.

like image 167
maximus ツ Avatar answered Sep 20 '22 17:09

maximus ツ