Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge conflict in .gitignore

Tags:

git

github

I have 2 branches, master and newfeature. When I want to merge newfeature into master, I used:

git checkout master git merge newfeature 

I get the error:

Auto-merging .gitignore CONFLICT (content): Merge conflict in .gitignore Automatic merge failed; fix conflicts and then commit the result. 

I opened up .gitignore and it looks like a mess now with the last part of the file looking like

<<<<<<< HEAD public/img/ignore ======= public/img/profiles public/blog public/recommendation >>>>>>> newfeature 

What happened, and how should this be fixed so that I can merge the branch into master?

like image 723
Nyxynyx Avatar asked Aug 28 '12 13:08

Nyxynyx


People also ask

How do I ignore a merge conflict?

The simplest way, if you have unmerged paths, use git merge --abort to abort the merge. This way your code will look the same as it was before trying to merge with some other branch...

How do I resolve merge conflicts in git?

Note the list of conflicted files with: git status (under Unmerged paths section). Solve the conflicts separately for each file by one of the following approaches: Use GUI to solve the conflicts: git mergetool (the easiest way). To accept remote/other version, use: git checkout --theirs path/file .

Can git automatically resolve merge conflicts?

When you pull or merge branches, Git will select the recursive strategy as default. The recursive strategy only can detect and do merges which involve renames, but cannot use detected copies. The ours option forces conflicted parts to be automatically resolved by favoring 'our' version.


2 Answers

You edited the .gitignore in both branches. Now, git is unsure of which lines in each copy are the correct ones so it is asking you to resolve them.

The lines:

<<<<<<< HEAD public/img/ignore ======= 

Are what appears in the copy of the file in master.

And

======= public/img/profiles public/blog public/recommendation >>>>>>> newfeature 

in the branch newfeature

You should just have to edit the file as you would like it to appear finally. Then...

git add .gitignore git commit 
like image 59
D-Rock Avatar answered Oct 15 '22 01:10

D-Rock


Simply edit .gitignore file to resolve conflict:

Before

<<<<<<< HEAD public/img/ignore ======= public/img/profiles public/blog public/recommendation >>>>>>> newfeature 

After

public/img/ignore public/img/profiles public/blog public/recommendation 

Then:

git add .gitignore

git commit

Autogenerated commit message should apear, accept it (save & close) and it's done.

like image 41
Łukasz Strzałkowski Avatar answered Oct 15 '22 00:10

Łukasz Strzałkowski