Let’s say I have 2 branches : A and B (let’s presume B is a split from A)
In branch A, I have changed the content of a file root/blabla/ariel1.txt
In branch B, I have changed the path to ariel1.txt
and rename it, so now it is called ariel2.txt
, and the path to it is: root/yadayada/ariel2.txt
Now, I decide to merge branch A into branch B.
How does git knows to merge the changes ariel1.txt
(in branch A) to ariel2.txt
(in branch B)?
I encountered in such case , and git didn’t know how to handle it correctly. any ideas how to overcome such case?
CodePudding user response:
How does git knows to merge the changes ariel1.txt (in branch A) to ariel2.txt (in branch B)?
It doesn't. Of course, you do. You have a notion of independently moving or renaming the file, as an action orthogonal to editing the file; but Git does not.
As Git sees it, in one branch the file was edited; in the other branch it was deleted. Those are conflicting fates, because being edited implies not being deleted; and Git rightly turns to you to resolve the conflict.
Solution: Resolve it and move on. Merge conflicts are not bad or uncommon; learn to cope with them.
CodePudding user response:
Git doesn't store renames and copies. Instead, it checks to see if files have similar content. If branch A changed the content too much, Git won't recognize it as a rename. You can control what it considers a rename with --find-renames.