我如何使用vimdiff解决冲突? [英] How do I use vimdiff to resolve a conflict?

查看:603
本文介绍了我如何使用vimdiff解决冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在git中将一个分支合并到了我的主分支中,并且我得到了自动合并失败;修复冲突,然后提交结果。现在我运行 git mergetool 并打开vimdiff图片。我不知道如何使用vimdiff。这里的每个小组是什么意思,我应该如何着手解决合并冲突?

解决方案

所有四个缓冲区都提供了同一个文件的不同视图。左上角缓冲区(LOCAL)是文件在目标分支中的显示方式(您正在合并的内容)。右上角的缓冲区(REMOTE)是文件在源分支中的显示方式(您正在合并的位置)。中间缓冲区(BASE)是两者的共同祖先(所以你可以比较左右版本之间的差异)。



我可能弄错了关于以下几点。我认为合并冲突的根源在于,自BASE以来,这两个文件都改变了文件的相同部分; LOCAL将报价从双倍改为单倍,REMOTE进行了相同的更改,但也将背景值从一种颜色更改为一个URL。 (我认为合并不够聪明以致于所有对LOCAL的改变都在REMOTE中出现;它只知道LOCAL自BASE以来在REMOTE所在的相同位置进行了更改)。



在任何情况下,底部缓冲区都包含您可以实际编辑的文件 - 坐在工作目录中的文件。你可以做任何你喜欢的改变; vim 向您展示了它与每个顶视图的不同之处,它们是自动合并无法处理的区域。如果您不想要REMOTE更改,请从LOCAL提取更改。如果您希望更改LOCAL更改,请从REMOTE中进行更改。如果您认为REMOTE和LOCAL都是错误的,请从BASE中拔出。如果你有更好的主意,做一些完全不同的事情!最后,您在这里所做的更改是实际承诺的更改。


I just merged a branch into my master in git and I got Automatic merge failed; fix conflicts and then commit the result. Now I ran git mergetool and vimdiff opened with the image below. I don't know how to use vimdiff. What does each panel here mean and how should I proceed to fix the merge conflict?

解决方案

All four buffers provide a different view of the same file. The top left buffer (LOCAL) is how the file looked in your target branch (what you are merging into). The top right buffer (REMOTE) is how the file looked in your source branch (where you are merging from). The middle buffer (BASE) is the common ancestor of the two (so you can compare how the left and right versions have diverged from each other).

I may be mistaken on the following point. I think the source of the merge conflict is that both files have changed the same portion of the file since BASE; LOCAL has changed the quotes from double to single, and REMOTE has made the same change but also changed the background value from a color to a URL. (I think the merge is not smart enough to notice that all the changes to LOCAL are also present in REMOTE; it just knows that LOCAL has made changes since BASE in the same places that REMOTE has).

In any case, the bottom buffer contains the file you can actually edit—the one sitting in your working directory. You can make any changes you like; vim is showing you how it differs from each of the top views, which are the areas that the automatic merge couldn't not handle. Pull changes from LOCAL if you don't want the REMOTE changes. Pull changes from REMOTE if you prefer those to the LOCAL changes. Pull from BASE if you think both REMOTE and LOCAL are wrong. Do something completely different if you have a better idea! In the end, the changes you make here are the ones that will actually be committed.

这篇关于我如何使用vimdiff解决冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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