1

I have two branches in my project. Every branch contains Main.java in both.

  • I do some changes in Main.java in the first branch(add some method or whatever).
  • in the second branch, I move Main.java to another folder and do some another change inside a class(for example add some different method).

After that, I tried to merge first branch and a second branch. But git doesn't understand that it`s the same file and, as result, I have two files Main.java, but in different folders. One Main.java contains changes from the first branch and another Main.java contains changes from the second branch.

When I commit changes on a second branch (with a moved file to another folder), then git shows me that file Main.java with the old path will be removed and Main.java with the new path will be added. As I understand, its have to say something just like "modified", "moved"...

I just need, that file will be in folder from second branch and contains changes from both branches. Or, at least, git understand that it's same file and show me Conflict(content), not Conflict(modify/delete).

Have any ideas about this?

Bobyk Egor
  • 21
  • 3
  • Possible duplicate of [Git: renamed file manually, Git confused](https://stackoverflow.com/questions/4708655/git-renamed-file-manually-git-confused) – Marek J Dec 13 '17 at 10:02
  • Puh, sounds nasty. I would either do one of the two things: Manullay integrate the changes from one branch to the other. Or: Move the file back to it's original location, merge, [fix conflicts], move file. I'm eager to know if there is a better solution. – Korashen Dec 13 '17 at 10:05

1 Answers1

0

So, actually, I force some git documentation and find next string:

"Git should consider a delete/add pair to be a rename if more than 90% of the file hasn’t changed."

As this project was test project, Main.java has just one method. And in second branch I change this method for another method and this means that it's more than 90% changes. So git do "delete/add" instead "modify".

Bobyk Egor
  • 21
  • 3
  • The default is actually a "50% similarity index", with the similarity index value computation being quite obscure, but in general, yes, that's the problem. You can alter the threshold for similarity detection: `git merge -X find-renames=`, e.g., `-X find-renames=05` means "consider it a rename even if it's only 5% similar". – torek Dec 13 '17 at 16:00