문제

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

도움이 되었습니까?

해결책 3

a--b--c--M--d--f--E--g--h--i  <<< master
    \
     \
      x--M'--y--z              <<< you

does your situation looks somewhat like above (where M and M' are the commits moving and E is the commit that edits the textures)? you try to merge z/i and git is not really happy.

you might try to merge M with M' on a temporary branch

a--b--c---M--d--f--E--g--h--i  <<< master
    \      \
     \      X                  <<< helper
      \    /
       x--M'--y--z             <<< you

and then merge helper ("X") with you ("z") and master ("i").

a--b--c---M--d--f--E--g--h--i     <<< master
    \      \                 \ 
     \      X-----XX---------XXX  <<< helper
      \    /      /
       x--M'--y--z                <<< you

that way conflicts are resolved directly after they are created and not carried along. often this is easier because conflicts tend to grow over time.

다른 팁

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.

While resolving conflicts just use git checkout indicating the right tree-ish (branch name, tag, sha1 of the commit...) from where you want to get a file:

git checkout theirBranchYouAreMerging -- textures/texture1.png

If you don't want all "their" changes, you could then cancel them partially. For that you would need git reset -p for selectively removing any undesirable change from the index, and then git checkout to remove them from the working directory as well:

git checkout theirBranch -- some/file.txt
git reset -p -- some/file.txt
git checkout -- some/file.txt
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top