在一个分支中,我重命名了文件。 在其他分支中我移动了文件。 我将主分支与两个分支 merge 。 现在我在主分支中有两个文件,并且在 merge 期间没有冲突。 Git 应该有这样的行为吗?我预计至少会发出警告。
编辑:控制台给了我警告。所以这是egit问题。 (Egit是eclipse插件)
最佳答案
行为正常,因为您在没有 git mv
的情况下重命名了文件; git 正确检测到文件重命名,但没有提交旧文件的删除,因此 merge 后现在您拥有两个文件。
使用 git mv
或 mv
后跟 git rm oldfile
会正确地导致 merge 冲突。
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.
关于Git merge 移动并重命名的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10188316/