Force git to recognize that a file has moved when merging

Go To


I'm developing a piece of software which is built on top of an open source project but contains some proprietary changes. Recently, there has been a big update to the open source project which has moved a bunch of files. For example:

app/models/my_model.rb --> app/models/namespace/my_namespaced_model.rb

There are a lot of files which were moved, and some of them have a lot of changes. So git is not merging the files, but is just saying that the old files have been "deleted by them" and marking it as a merge conflict. The thing is, if there were simply a few less changes so that git could realize that the file had been moved, rather than thinking it was deleted and a new one was created, I think it would sort out most of the changes easily. As it stands, it looks like I need to go through and make all the old changes to the new files by hand.

So my question is, is there any way to force git to realize that a file has been moved when it can't figure it out automatically?

2012-04-04 17:46
by alexsanford1


The recursive strategy that git merge uses by default has a "rename-threshold" option that you may be able to change to help. You may have to experiment to find the best setting.

git merge -X rename-threshold=70 mybranch

The setting has the same effect as in git diff -M and is described in the git diff manpage.

2012-04-04 18:16
by CB Bailey
I'm getting this: "fatal: Unknown option for merge-recursive: -Xrename-threshold=70". I've also been trying to use options such as "ignore-space-change" because some of the files have indentation changes, but getting the same error. I'm using git 1.7.1 on Ubuntu 10.10. Do I need a newer version - alexsanford1 2012-04-04 18:47
Typo, it's -X ... (with a space) - torek 2012-04-04 18:55
@torek: updated. In future, feel free to fix typos yourself - CB Bailey 2012-04-04 19:05