0

I have two branches that I try to merge. In the original branch I have some files that in the 2nd branch where moved to a different location. the problem is that when I try to merge from the original branch, it doesn't apply the changes to the new file location even tough it detected that I moved the files with git move.

I created the following scenario to better explain my problem:

I have branch a with files a/1.txt, a/2.txt. in branch b I did git mv to 1.txt and 2.txt from directory a to b.

next.. in branch a I modified a/1.txt, in branch b when I try merge branch a into it, it tries to create a/1.txt instead of applying the change on the new file's location (in directory b).

how do I resolve this issue ?

4

1 回答 1

1

我提供了一个小例子,很可能显示了您的问题:

mkdir test
cd test/
git init
echo -e '1\n2\n3' >foo
git add foo
git commit -m foo
git checkout -b bar
echo -e '1\n4\n5' >bar
rm foo
git add --all .
git commit -m bar
git checkout -
echo -e '6\n2\n3' >foo
git add foo
git commit -m foo2
git merge bar

现在你得到一个错误说

# CONFLICT (modify/delete): foo deleted in bar and modified in HEAD. Version HEAD of foo left in tree.
# Automatic merge failed; fix conflicts and then commit the result.

如果您改为降低识别重命名所需的相似度-X find-renames=30%(相似度为 33%,因为三行之一相同),则合并效果更好:

git merge --abort
git merge bar -X find-renames=30%
git mergetool
git commit --no-edit
于 2017-02-02T14:29:16.827 回答