【问题标题】:Git conflict "both deleted"Git冲突“都已删除”
【发布时间】:2017-12-06 12:56:14
【问题描述】:

我不明白为什么“都已删除”是未合并路径的状态。

如果:

  • 旧标准是基础
  • NewStandard 是主干上的最后一次提交
  • OldCustom 是我们尝试在 master 中合并的分支(来自 OldStandard 的分支)

为什么与标记为“都已删除”的某些文件发生冲突?

我了解在 NewStandard 中添加一个文件,而在 OldCustom 中添加该文件的另一个版本时,“都添加”的冲突。

但是,对于删除,如果文件在 NewStandard 中已删除,并且在 OldCustom 中也已删除,会有什么问题?那是一个等效的状态,不是吗?

【问题讨论】:

标签: git merge conflict delete-file


【解决方案1】:

this answer 中所述(建议重复):

branchA 有一个git mv oldfile newstandard 提交,而branchB 有一个git mv oldfile newcustom 提交时,您可以看到“都已删除”。

在这种情况下,当尝试将customBranch 合并到standardBranch 时,git 将报告三个文件的冲突:

both deleted:  oldfile
added by them: newcustom
added by us:   newstandard

就像任何冲突一样,最终的选择权在你手中:

git 只是强调可能在您的最终代码版本中newcustomnewstandard 一起存在这一事实可能存在问题,并且可能 em> 这可能与两者都是通过作为oldfile 的副本创建的事实有关。

您可以手动修复它:

  • 如果删除 oldfile 是预期结果:git reset -- oldfile
  • 如果保留newstandard 是预期结果,请删除另一个:git reset newcustom && git rm newcustom
  • 如果newstandardnewcustom 的某些部分应该合并:手动编辑它们,或使用三向合并工具:meld newstandard newstandard newcustom
  • 等等...

【讨论】:

  • 在这种情况下,我们如何决定要保留哪些东西?接受删除是有意义的,然后在完成合并时接受newcustomnewstandard。但是我们如何才能清楚地看到我们必须在这两个文件之间做出选择(当有数百个冲突时)?在这里使用 git mergetool 没有帮助,对吗?
  • @user3341592:你是对的,mergetool 只会在解决单个文件上的“两个修改”冲突时向您显示“正确的”3 路合并。
猜你喜欢
  • 2011-11-12
  • 1970-01-01
  • 2011-03-08
  • 1970-01-01
  • 1970-01-01
  • 2015-08-27
  • 1970-01-01
  • 1970-01-01
  • 2011-12-19
相关资源
最近更新 更多