How to fix conflicts in git?

£可爱£侵袭症+ 提交于 2019-12-23 12:03:05

问题


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

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.


回答1:


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

Solving git conflict using text editor.

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

  1. Whenever there is conflict in a file git add conflict marker that looks like this <<<<<<<<.

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

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

  4. 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"

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.

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 

you can solve merge conflicts

git mergetool -t meld

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



来源:https://stackoverflow.com/questions/47588838/how-to-fix-conflicts-in-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!