在GitHub仓库上创建文件的副本,但用于不同的内容。

huangapple go评论70阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年3月7日 07:02:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75656609.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定