Alex B
Alex B

Reputation: 84892

Why doesn't git attempt to merge changes to renamed files?

Let's say I have a file that's

  1. Modified in master
  2. Modified in a feature branch
  3. Renamed in a feature branch

When I try to merge up from master to the feature branch, merge fails with

CONFLICT (modify/delete): X deleted in HEAD and modified in origin/master. Version origin/master of X left in tree.

I understand that there is a conflict, but why doesn't it even try to merge changes and place conflict markers in the file? Previous answers seem to imply that it should. All I get is two different versions of the file, where I have to figure out the difference manually and port changes line by line from master version to my version.

Steps to reproduce:

git init
touch a
git add a
git commit -m 'initial import'

git checkout -b feature1
echo feature1 > a
git add a
git commit -m feature1
git mv a b
git commit -m feature1

git checkout master
echo bugfix > a
git add a
git commit -m bugfix

git checkout feature1 
git merge master 

Upvotes: 19

Views: 6403

Answers (1)

akent
akent

Reputation: 4188

Because there is actually no concept of first-class rename operation in git, it just "detects" renames using a threshold for file differences. Your files are probably too different.

Try merging with: git merge master -s recursive -X rename-threshold=5%

Upvotes: 32

Related Questions