如何解决git中的冲突? [英] How to fix conflicts in git?

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

问题描述

当我尝试拉动时,会显示以下消息:

When I try to pull I have the following message:

Automatic merge failed; fix conflicts and then commit the result.

因此,我尝试按照

So, I try to fix conflict (as git suggest) for that I follow these instructions.

首先需要做的是在文本编辑器中打开有问题的"文件,并找到类似的行

Among the first things that I need to do is to open the "problematic" file in a text editor and find lines like that

If you have questions, please
<<<<<<< HEAD
open an issue
=======
ask your question in IRC.
>>>>>>> branch-a

问题是我在文件中看不到类似内容.特别是我搜索了HEAD,但它不存在.

The problem is that I do not see things like that in my file. In particular I searched for HEAD and it is not there.

推荐答案

有几种解决git冲突的方法,在这里我将使用GUI和文本编辑器方法进行解释.

There are several ways to solve git conflicts, I will explain here using GUI and text editor way.

打开任何您喜欢的编辑器,例如记事本,gedit,vim,nano甚至是Eclipse.

Open any one of your favourite editor, example, Notepad, gedit, vim, nano or even Eclipse.

  1. 只要文件git中有冲突,就添加看起来像<<<<<<<<的冲突标记.

在文本编辑器中打开文件时,您会在<<<<<<< HEAD

When you open the file in your text editor, you'll see the changes from the HEAD or base branch after the line <<<<<<< HEAD

========,它将您对其他分支的更改划分为>>>>>>>>YOUR_BRANCH_NAME

========, it divides your changes from the other branch as >>>>>>>>YOUR_BRANCH_NAME

您可以决定是否要保留分支更改.如果要保留所做的更改,请删除冲突标记,<<<<<<<, =======, >>>>>>>,然后进行合并.

You can decide if you want keep your branch changes or not. If you want to keep the changes what you did, delete the conflict marker they are,<<<<<<<, =======, >>>>>>> and then do a merge.

用于提交更改的命令.

Commands to commit the changes.

git add . or git add "your_file"
git commit -m "Merge conflicts resolved"


解决git与您的GUI冲突

如果文件中有太多合并冲突该怎么办?在这种情况下,您可以使用GUI,是否选择GUI只是个人选择.在GUI中,您可以看到并排差异.初学者很容易看到更改.


Solving git conflict your GUI

What if you have so many merge conflicts in files? In that case you can use GUI, well its just personal choice whether to opt for GUI or not. In GUI, you can see side by side diff. It is easy for the beginners to see the changes.

您需要配置git以使用要使用的mergetool.例如:meld,kdiff3或vimdiff.再次由用户决定他们喜欢什么.我使用融合.在这里您需要安装这些工具,安装后必须对其进行配置.

You need to configure your git to use the mergetool you want to use. Example: meld, kdiff3 or vimdiff. Again it's upto the user what they prefer. I use meld. Here you need to install these tool, after installation you have to configure it.

git config merge.tool meld 

您可以解决合并冲突

git mergetool -t meld

然后,您可以按照第2步到第4步进行操作,使用文本编辑器解决合并冲突.

Then you can follow the step 2 to 4 from solving using text editor, to solve the merge conflicts.

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

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