如何解决由于删除分支中的文件而导致的合并冲突?
我创建了一个 dialog
分支,当我尝试将其合并到 master
分支时。有2个冲突。我不知道如何解决冲突(删除/修改)
。你能告诉我该怎么做吗?
$ git checkout master
$ git merge dialog
CONFLICT (delete/modify): res/layout/dialog_item.xml deleted in dialog and modified in HEAD. Version HEAD of res/layout/dialog_item.xml left in tree.
Auto-merging src/com/DialogAdapter.java
CONFLICT (content): Merge conflict in src/DialogAdapter.java
Automatic merge failed; fix conflicts and then commit the result.
我已打开 src/DialogAdapter.java,修复了冲突并执行了 git add src/DialogAdapter.java 。我还需要做什么?
I have create a dialog
branch and when I try to merge it to master
branch. There are 2 conflicts. I don't know how to resolve CONFLICT (delete/modify)
. Can you please tell me what to do?
$ git checkout master
$ git merge dialog
CONFLICT (delete/modify): res/layout/dialog_item.xml deleted in dialog and modified in HEAD. Version HEAD of res/layout/dialog_item.xml left in tree.
Auto-merging src/com/DialogAdapter.java
CONFLICT (content): Merge conflict in src/DialogAdapter.java
Automatic merge failed; fix conflicts and then commit the result.
I have opened src/DialogAdapter.java
, fixed the conflict and did a git add src/DialogAdapter.java
. What else do I need to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您有 2 个冲突:
res/layout/dialog_item.xml
在一个分支中更改,并在另一个分支中删除src/DialogAdapter.java
在两个分支中更改第二个你解决了。剩下的就是决定是否要删除
res/layout/dialog_item.xml
还是离开。在第一种情况下,您git rm
它,在第二种情况下git add
。然后执行git commit
。重现冲突:
You have 2 conflicts:
res/layout/dialog_item.xml
was changed in one branch and deleted in the other onesrc/DialogAdapter.java
was changed in both branchesThe second one you resolved. What's left is to decide whether you want to deleted
res/layout/dialog_item.xml
or leave. In the first case yougit rm
it, in the secondgit add
. Then dogit commit
.To reproduce the conflict:
我遇到了类似的问题,但就我而言,这是对项目的拉取请求,该项目既不属于我,也没有写入权限。以下步骤会有所帮助:
res/layout/dialog_item.xml
)dialog
)中删除这些文件,然后推送到远程(master)(git rm path
)。现在,您将看到冲突已解决。
I stuck with similiar problem but in my case it was a pull request on project that is neither owned by me nor i have write access. Following steps will be helpful:
res/layout/dialog_item.xml
)dialog
) then push to remote(master) (git rm path
).Now, you will be see conflicts are resolved.
冲突消息:
表示
res/layout/dialog_item.xml
在您要合并的“dialog”分支中被删除,但在 HEAD 中进行了修改(在您要合并到的分支中)。因此,您必须决定是
git rm res/layout/dialog_item.xml
”删除文件,还是
git add res/layout/dialog_item”从 HEAD 接受版本(可能在编辑后) .xml
”然后用“
git commit
”完成合并。请注意,git 会警告您正在创建合并提交,在(罕见)情况下,这是您不想要的。可能是上述病例不太罕见的时候遗留下来的。
The conflict message:
means that
res/layout/dialog_item.xml
was deleted in the 'dialog' branch you are merging, but was modified in HEAD (in the branch you are merging to).So you have to decide whether
git rm res/layout/dialog_item.xml
"or
git add res/layout/dialog_item.xml
"Then you finalize merge with "
git commit
".Note that git will warn you that you are creating a merge commit, in the (rare) case where it is something you don't want. Probably remains from the days where said case was less rare.
我通常只运行 git mergetool ,它会提示我是否要保留修改的文件或将其删除。恕我直言,这是最快的方法,因为它是一个命令,而不是每个文件多个命令。
如果您在特定的子目录中有一堆已删除的文件,并且您希望通过删除文件来解决所有问题,您可以这样做:
提供
d
来选择删除每个文件。您还可以使用m
来保留修改后的文件。取自运行mergetool
时看到的提示:I normally just run
git mergetool
and it will prompt me if I want to keep the modified file or keep it deleted. This is the quickest way IMHO since it's one command instead of several per file.If you have a bunch of deleted files in a specific subdirectory and you want all of them to be resolved by deleting the files, you can do this:
The
d
is provided to choose deleting each file. You can also usem
to keep the modified file. Taken from the prompt you see when you runmergetool
:如果您在 Windows 上使用 Git Gui,
If you are using Git Gui on windows,