If I attempt to reproduce your issue I get a rename/rename conflict, as I would expect. First, I created a repository and some files (with unique contents):
$ mkdir rename-exp
$ cd rename-exp/
$ git init
Initialized empty Git repository in /home/torek/tmp/rename-exp/.git/
$ cat > 1
This is file "1" in its initial state.
The file is being used
for a test of what happens with
a rename vs rename conflict
in Git.
The file needs some contents
so that git can detect the
rename when we actually
do the rename.
$ cat > 2
This is file "2".
We give it some contents
so that it has a unique SHA-1.
$ git add .
$ git commit -m initial
[master (root-commit) a4b6f52] initial
2 files changed, 12 insertions(+)
create mode 100644 1
create mode 100644 2
Next, I create branch b
and rename. Note that it will not matter whether I do the rename with git mv
or with mv
followed by git rm --cached
and git add
(but git mv
is easier, so I use it). It is, however, important that git be able to detect the rename. This requires that either the files match 100% exactly (the easy case) or that they match "at least 50%" (this threshold can be adjusted, but 50% is the default) when diff-ed and that the old name (1
) is no longer present in both trees at the time of the git merge
.
$ git checkout -b b
Switched to a new branch 'b'
$ git mv 1 1_b
$ git commit -m 'rename 1 to 1_b in branch b'
[b cc104b1] rename 1 to 1_b in branch b
1 file changed, 0 insertions(+), 0 deletions(-)
rename 1 => 1_b (100%)
Then I do the same rename, with a different name-target, in master
:
$ git checkout master
Switched to branch 'master'
$ git mv 1 1_master
$ git commit -m 'rename 1 to 1_master in master'
[master b891757] rename 1 to 1_master in master
1 file changed, 0 insertions(+), 0 deletions(-)
rename 1 => 1_master (100%)
Finally, I run git merge
:
$ git merge b
CONFLICT (rename/rename): Rename "1"->"1_master" in branch "HEAD" rename "1"->"1_b" in "b"
Automatic merge failed; fix conflicts and then commit the result.
$
You'll need to show your steps (and perhaps your git version as well) in order for me to see why your merge thought each change was delete-and-create (with non-conflicting creates) rather than rename.
Other variables that affect this:
- any argument to
-X rename-threshold
during the merge (this is how you tune the 50% default);
- the value from
git config --get merge.renameLimit
- the value from
git config --get diff.renameLimit
, if there is no setting for merge.renameLimit
.