Git merge 移动并重命名的文件

标签 git egit

在一个分支中,我重命名了文件。 在其他分支中我移动了文件。 我将主分支与两个分支 merge 。 现在我在主分支中有两个文件,并且在 merge 期间没有冲突。 Git 应该有这样的行为吗?我预计至少会发出警告。

编辑:控制台给了我警告。所以这是egit问题。 (Egit是eclipse插件)

最佳答案

行为正常,因为您在没有 git mv 的情况下重命名了文件; git 正确检测到文件重命名,但没有提交旧文件的删除,因此 merge 后现在您拥有两个文件。

使用 git mvmv 后跟 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/

相关文章:

android - 在 eclipse 中使用 egit 导入 android 依赖项目的最佳 git 结构

eclipse - egit 替换单个文件 - git 索引中的 HEAD 修订与文件

git - 如何在 Git 中比较本地主机和远程主机?

git - 持续集成工作流程 - 紧急用例

git - Git 中添加但未提交的删除文件能否恢复?

git - 我可以影响 gitk 和 Eclipse Egit 中显示的分支顺序/列吗

java - 使用 git 存储库在 Eclipse 中管理 Maven 项目

git - 移动了一个 git repo - 现在每个文件都有一个未暂存的更改..(权限?)

python - 如何在 python 中构造 git diff 查询

eclipse - Eclipse Git(EGit)远程:无效的数据包行 header