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

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

问题描述

我刚刚在 git 中将一个分支合并到我的 master 中,但我得到了 自动合并失败;修复冲突,然后提交结果. 现在我运行 git mergetool 并打开 vimdiff,如下图所示.我不知道如何使用 vimdiff.这里的每个面板是什么意思,我应该如何解决合并冲突?

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?

推荐答案

所有四个缓冲区都提供同一文件的不同视图.左上角的缓冲区 (LOCAL) 是文件在您的目标分支中的外观(您正在合并的内容).右上角的缓冲区 (REMOTE) 是文件在源分支(从何处合并)中的外观.中间缓冲区 (BASE) 是两者的共同祖先(因此您可以比较左右版本彼此之间的分歧).

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

我可能在以下几点上有误.我认为合并冲突的根源是两个文件自 BASE 以来都更改了文件的同一部分;LOCAL 将引号从双引号更改为单引号,而 REMOTE 进行了相同的更改,但还将背景值从颜色更改为 URL.(我认为合并不够聪明,无法注意到对 LOCAL 的所有更改也出现在 REMOTE 中;它只知道 LOCAL 自 BASE 以来在 REMOTE 的相同位置进行了更改).

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

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

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 解决 git 合并冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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