-1

I have just started working on github, so I am sorry in advance if my question seems foolish to you.

I was learning git hub and here was the problem that I am tackling. I have two branches, say master and second-branch I have had a readme.txt file inside the master branch having the following content:

This line lies inside the master branch

And this line as well

In the second-branch I have had a readme.txt file as well having the following content:

This line lies inside the secondbranch

And this line as well

After that I went back to the master branch by using git checkout master and tried merging these two branches by using the following command: git merge second-branch

Now when I tried merging these branches, it gave me a conflict error and now the readme.txt file inside the master branch had became something like the following:

This line lies inside the master branch
<<<<<<< HEAD
This line lies inside the secondbranch
=======
And this line as well

>>>>>>> second-branch

Can anyone please tell me what I am doing wrong here and how may I get this to work?

Plus what comes in my mind is that the content that lies at the same line numbers, git gives the error to merge them... Now I wonder, in case when I'd be working on some large project and I had to change something in a file having a large number of Lines of code in a new branch, I'd surely change something at the line upon which a different code lies inside the master branch, upon merging it'd mess up all my code giving this error and the modifying the file in the master branch. Wouldn't it?

Thanks.

Community
  • 1
  • 1
FAISAL
  • 459
  • 8
  • 22
  • 1
    You are not doing anything wrong. Git cannot merge the files and needs human intervention to produce the right result. Fix the conflict, stage the file and commit the merge. – knittl Sep 25 '13 at 13:25

1 Answers1

3

That isn't an error.

You added the lines in both branches and Git isn't able to determine which one it should use. So it reports a conflict and marks the lines so that you can compare them. You need to determine what the line should be.

This generally only happens when a change is made to the same line in both branches. It isn't a common occurrence but isn't anything to worry about.

If you do a git status, you will see the file marked as 'changed by both'.

Do these steps to resolve the conflict:

git mergetool //This will open a text editor with the files compared so that you can determine the change to use
git commit

http://githowto.com/resolving_conflicts

Schleis
  • 41,516
  • 7
  • 68
  • 87