I have two branches. In one branch I only renamed files with git mv. In another branch some of those same files were modified. I would like to merge the latter branch into the former. I would think that since git knows about the rename operation this would not be a problem, yet this is not what I am seeing
Here is a scaled down experiment demonstrating the issue:
/tmp/gittest λ git init
Initialized empty Git repository in /private/tmp/gittest/.git/
/tmp/gittest:no-branch*? λ touch foo
/tmp/gittest:no-branch*? λ git add foo
/tmp/gittest:no-branch*? λ git commit -m initial
[main (root-commit) 532197b] initial
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 foo
/tmp/gittest:main? λ git checkout -b moved
Switched to a new branch 'moved'
/tmp/gittest:moved? λ git mv foo foo.moved
/tmp/gittest:moved*? λ git commit -m 'move it'
[moved 384b27d] move it
1 file changed, 0 insertions(+), 0 deletions(-)
rename foo => foo.moved (100%)
/tmp/gittest:moved? λ git checkout main
Switched to branch 'main'
/tmp/gittest:main? λ ls
foo
/tmp/gittest:main? λ echo "v2" > foo
/tmp/gittest:main*? λ git add foo
/tmp/gittest:main*? λ git commit -m 'changed'
[main 25c98d1] changed
1 file changed, 1 insertion(+)
/tmp/gittest:main? λ git checkout moved
Switched to branch 'moved'
/tmp/gittest:moved? λ ls
foo.moved
/tmp/gittest:moved? λ git merge main
CONFLICT (modify/delete): foo deleted in HEAD and modified in main. Version main of foo left in tree.
Automatic merge failed; fix conflicts and then commit the result.
I get a similar result with rebase.
I am aware that git stores tree states not diffs, but I thought the fact that git explicitly knew about the rename would help with that.
What is going on and what is the correct approach here?