为什么git给我一个“删除的合并冲突”当双方都被删除? [英] Why is git giving me a "deleted merge conflict" when both sides are deleted?

查看:1148
本文介绍了为什么git给我一个“删除的合并冲突”当双方都被删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 master 的更新版本合并到我的分支中。在主文件中,我删除了一个文件。 Git为我提供了以下内容:

 删除了'Lib / SharedBL / WebServices / WebAPI / Admin / Admin.cs'的合并冲突: 
{local}:已删除
{remote}:已删除
使用(m)修饰或(d)已选文件或(a)bort?

为什么这是冲突?双方都被删除,所以git应该删除它?

解决方案

首先,我们需要一点背景术语。当你运行 git merge xyz 时,Git识别三个提交:


  • 您当前的提交: HEAD ,local, - 我们的等等。我喜欢将这个 L 称为Left或Local。

  • 另一个提交:由 xyz :remote,other, - 他们的等等。我喜欢将这个 R 称为Right或Remote。
  • 第三个提交:第一个是 L R 有提交。这是 merge base 提交。


Git计算从合并基底到 L的差异,以及从合并基础到 R 的第二个差异。如果 Lib / SharedBL / WebServices / WebAPI / Admin / Admin,这两个diff可以对合并基础中存在的文件进行不同的更改。

cs 是合并基础提交中的一个文件,并且在两个头都被删除,不会发生冲突,并且不会发生。



但是,如果合并库中存在 Lib / SharedBL / WebServices / WebAPI / Admin / Admin.cs 并被重命名(也可能被修改)在另一个提交中的删除中,会有重命名/删除冲突。在这种情况下, git mergetool 将无法找到 Lib / SharedBL / WebServices / WebAPI / Admin / Admin.cs 换句话说,该特定文件将在工作树中被删除。 但是...应该是吗?你应该从基本提交还原文件吗? git mergetool 脚本不知道。它提出了这个问题。



请注意,如果您从基本提交恢复文件,您仍然会拥有重命名的文件。这取决于你如何解决这个问题。


I'm merging an updated version of master into my branch. In master a file has been deleted that I also deleted. Git gives me the following:

Deleted merge conflict for 'Lib/SharedBL/WebServices/WebAPI/Admin/Admin.cs':
  {local}: deleted
  {remote}: deleted
Use (m)odified or (d)eleted file, or (a)bort?

Why is this a conflict? Both sides are deleted so surely git should just delete it?

解决方案

First, we need a quick bit of background terminology. When you run git merge xyz, Git identifies three commits:

  • Your current commit: HEAD, "local", --ours, and so on. I like to call this L for Left or Local.
  • The other commit: the one identified by xyz: "remote", "other", --theirs, and so on. I like to call this R for Right or Remote.
  • A third commit: the first one that L and R had in commit. This is the merge base commit.

Git computes a diff from the merge base to L, and a second diff from the merge base to R. The two diffs can make different changes to files that existed in the merge base.

If Lib/SharedBL/WebServices/WebAPI/Admin/Admin.cs was a file in the merge base commit and is deleted in both heads, there will be no conflict, and this would not occur.

However, if Lib/SharedBL/WebServices/WebAPI/Admin/Admin.cs existed in the merge base and was renamed (and maybe also modified) in one commit but deleted in the other commit, there will be a rename/delete conflict. In this case, git mergetool will not find Lib/SharedBL/WebServices/WebAPI/Admin/Admin.cs in either L or R.

That particular file will, in other words, be deleted in the work-tree. But ... should it be? Should you restore the file from the base commit? The git mergetool script doesn't know. It presents you with this question.

Note that if you restore the file from the base commit, you'll still have the renamed file as well. It's up to you to figure out what to do about this.

这篇关于为什么git给我一个“删除的合并冲突”当双方都被删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆