英文:
Create copy of file on github repo but use it for different content
问题
我在GitHub上有一个名为test1.py的文件。
我想使用它的所有内容,只改变1行。所以我创建了一个新分支,复制了test1.py,然后删除了test1.py,然后将它粘贴到同一仓库的不同位置。然后将其重命名为test2.py。然后改变了1行。
然后我想要将主分支与我的分支合并。
所以当我尝试这样做时,GitHub认为test1.py和test2.py是相同的,只是移动到了不同的位置,所以我遇到了合并冲突(因为有1行已更改)。
如何避免GitHub将test2.py视为test1.py?
我在上面已经解释了。
英文:
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
得分: 1
我怀疑你可能想要在你的新分支中 保留 test1.py
,并在 test2.py
中复制它。
这样,从主分支合并时,不会认为 test2.py
是 test1.py
重命名。
另一个选项是使用 no-rename
选项来执行合并策略,该选项会考虑到这一点:
git merge -s recursive -X no-renames
正如IMSoP 在评论中指出的,默认的合并策略ORT(在Git 2.30, 2021年第一季度引入)会忽略该选项。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论