在一个分支中,我重命名了文件。在其他分支中,我移动了文件。我将主分支与两个分支合并。现在我在主分支中有两个文件,合并过程中没有冲突。Git 应该那样表现吗?我期待至少警告。
编辑:控制台给我警告。所以这是 egit 问题。(Egit 是日食插件)
行为是正常的,因为您在没有git mv
的情况下重命名了文件; git 正确检测到文件重命名,但没有提交删除旧文件,因此合并后您现在拥有两个文件。
使用 git mv
或 mv
后跟git rm oldfile
,则会导致合并冲突。
Initialized empty Git repository
$ echo "hello" > hello.txt
$ git add hello.txt && git commit -m "first"
[master (root-commit) 708ec5f] first
1 file changed, 1 insertion(+)
create mode 100644 hello.txt
$ git branch mybranch
$ git mv hello.txt hello2.txt
$ git commit -m "renamed"
[master 00c68ed] renamed
1 file changed, 0 insertions(+), 0 deletions(-)
rename hello.txt => hello2.txt (100%)
$
$ git checkout mybranch
Switched to branch 'mybranch'
$ mkdir test
$ git mv hello.txt test
$ git commit -m "moved"
[mybranch 044e091] moved
1 file changed, 0 insertions(+), 0 deletions(-)
rename hello.txt => test/hello.txt (100%)
$ git checkout master
Switched to branch 'master'
$ git merge mybranch
CONFLICT (rename/rename): Rename "hello.txt"->"hello2.txt" in branch "HEAD" rename "hello.txt"->"test/hello.txt" in "mybranch"
Automatic merge failed; fix conflicts and then commit the result.