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

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

问题描述

我刚刚在git中将一个分支合并到了我的主服务器中,我得到了Automatic merge failed; fix conflicts and then commit the result.现在我运行了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. (我认为合并不够聪明,无法注意到RECALE中也存在对LOCAL的所有更改;它只是知道自BASE以来,LOCAL已在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中提取更改.如果您喜欢从本地更改,请从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天全站免登陆