Al3xophis
Al3xophis

Reputation: 37

Git merge conflict detected after moving some files

We are currently dealing with a bunch of files, all tracked on a git repository. At some point, we had to move part of those files, we did it using :

git mv repo/file.c new_repo/

After some modifications on the "new_repo/file.c" (and by modification, I mean a lot of changes), we have to rebase on the main branch (in which files had not been moved).

Let's say on this branch "repo/file.c" has been modified, does GIT will detect merge conflicts between "new_repo/file.c" on the working branch & "repo/file.c" on the main branch? Are those files considered the same even if they has been modified a lot?

Upvotes: 0

Views: 155

Answers (2)

Schwern
Schwern

Reputation: 164809

Git does not store copies and renames, it tries to figure them out using heuristics. It doesn't always try hard. The default merge strategy (recursive) can be told to try harder.

rename-threshold=<n>
    Controls the similarity threshold used for rename detection.
    See also git-diff(1)-M.

The similarity threshhold is defined as...

(i.e. amount of addition/deletions compared to the file's size). For example, -M90% means Git should consider a delete/add pair to be a rename if more than 90% of the file hasn't changed. Without a % sign, the number is to be read as a fraction, with a decimal point before it. I.e., -M5 becomes 0.5, and is thus the same as -M50%. Similarly, -M05 is the same as -M5%. To limit detection to exact renames, use -M100%. The default similarity index is 50%.

I don't know what the default is for recursive merge, probably 50%. Try git merge -X rename-threshold=50% then 40%, 30% and so on.

Upvotes: 1

Jakub Narębski
Jakub Narębski

Reputation: 323464

Git will try to detect which files on one side of merge correspond to which files on other side of merge using similarity heuristics (how similar files and their filenames are).

It usually works O.K. If it doesn't, and you used incremental changes (i.e. change to files is gradual, commit by commit), you can try using git-imerge tool.

Upvotes: 1

Related Questions