1

I have a file in github called test1.py

I want to use all of its content and just change 1 line. So i created a new branch, copied test1.py, then deleted test1.py, and then pasted it in a different location in the same repo. Then renamed it to test2.py. Then changed 1 line.

Then what I wanted is to merge master with my branch.

So when I tried that , github thinks that test1.py is the same as test2.py and it is just moved to a different location, and i get a merge conflict(because of the 1 changed line )

How can I avoid that github sees test2.py like it us test1.py?

I explained above ,

1 Answers1

1

I suspect you might want to keep test1.py in your new branch, and duplicate it in test2.py.

That way, the merge from master won't think test2.py is test1.py renamed.

The other option is to use the no-rename option to a merge strategy which takes that option into account:

git merge -s recursive -X no-renames

As noted by IMSoP in the comments, the default merge strategy ORT (introduced with Git 2.30, Q1 2021) would ignore that option.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Nitpick: `-X no-renames` specifies an _option_ to the merge strategy, not a strategy itself. Also, if I'm reading the manual right, it is ignored by the "ort" strategy, which is now the default, so you would need to also specify the "recursive" strategy, as in `git merge -s recursive -X no-renames` – IMSoP Mar 07 '23 at 09:07
  • @IMSoP Good point, thank you. I have edited the answer accordingly. – VonC Mar 07 '23 at 09:10
  • Thank you, I will try option 2 tomorrow. Your first approach seems also good but in my case I already have 2 branches as described above , so keeping the test1.py is not possible anymore. I can't vote up this answer cause I have a new account unfortunately – Real Programmer Mar 09 '23 at 23:17