在一个分支中,我重命名了文件。 在其他分支我移动文件。 我将两个分支合并为主分支。 现在我在主分支中有两个文件,在合并期间没有冲突。 Git应该表现得如此吗?我希望至少有警告。Git合并移动并重命名文件
编辑:控制台给我waring。所以这是egit问题。 (Egit是eclipse插件)
在一个分支中,我重命名了文件。 在其他分支我移动文件。 我将两个分支合并为主分支。 现在我在主分支中有两个文件,在合并期间没有冲突。 Git应该表现得如此吗?我希望至少有警告。Git合并移动并重命名文件
编辑:控制台给我waring。所以这是egit问题。 (Egit是eclipse插件)
行为是正常的,因为你没有改名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.
不,它与不使用git mv无关。使用git mv会得到相同的结果。 – user482745 2012-04-17 12:01:14
不适合我;如果你'mv'但是不要'git rm'这个旧文件,后者将会保留下来。我在这里复制了一个简单的案例,我得到一个合并冲突 – CharlesB 2012-04-17 12:11:53
请参阅我的测试回购的抄本,遵循您描述的案例(移入一个分支,重命名另一个分支,并合并)。我正确地得到合并冲突 – CharlesB 2012-04-17 12:22:47
你使用'git mv'或者你是否使用shell命令重命名/移动文件? – 2012-04-17 09:13:42
我用过外壳。根据[链接](http://stackoverflow.com/questions/1094269/whats-the-purpose-of-git-mv)它应该没有关系。 – user482745 2012-04-17 09:17:37
你所关联的问题中接受的答案有一个评论(指git mv):“它也有一些内置的安全装置”。也许这是其中一种情况? – Edu 2012-04-17 09:22:26