简体   繁体   中英

Git merge two branches with moved files

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?

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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM