相关文章推荐
热心肠的香蕉  ·  git ...·  2 天前    · 
追风的鼠标  ·  【转】在'git ...·  1 周前    · 
高大的板栗  ·  合并到git后的git-svn ...·  1 周前    · 
含蓄的火腿肠  ·  Config file ...·  1 年前    · 
含蓄的松球  ·  【Flutter -- ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

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?

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:

public/img/ignore =======

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

=======
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

Fix the conflicts in the .gitignore file, add the updated version and then commit:

vim .gitignore
# assuming you want all 4 lines: simply remove the conflict markers (<<<<<<, ======, and >>>>>)
git add .gitignore
git commit

What happened is that there was a merge conflict: two branches changed the file "at the same time", in distinct streams. You can see the changes other branch has done in "newfeature" section and the other in the HEAD section.

What you need to do is to edit that file so that it will contain the contents that you want, add that to be followed and then commit that. This is known as a merge commit.

Now, what I told above is doing a merge by hand, "manually". It is possibly the easiest to understand. You can also use git mergetool command to do that with a visual tool, if configured, or use "git merge" with some strategy that will tell it how to handle the conflict.

Git's automatic merge failed. This usually happens when changes occur to the same file at the same time in different branches/repositories when trying to merge branches/push content.

The modifications made to .gitignore on the branch newfeature conflits with the one made on master. The line: <<<<<<< HEAD indicates the modifications made on master, which follow this line, while the line >>>>>>> newfeature indicates the modifications made on newfeature, which precede this line. The two modifications are separated by =======.

You should edit manually the file and keep/merge what is useful in each of the two parts. Then you should commit (after removing the <<<<HEAD , ===== and >>>newfeature lines).

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.