合并.gitignore中的冲突

时间:2012-08-28 13:47:54

标签: git github

我有2个分支,masternewfeature。当我想将newfeature合并到master时,我使用了:

git checkout master
git merge newfeature

我收到错误:

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

我打开.gitignore现在看起来像一团糟,文件的最后一部分看起来像

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

发生了什么,以及如何解决这个问题,以便我可以将分支合并到master

7 个答案:

答案 0 :(得分:20)

您在两个分支中编辑了.gitignore。现在,git不确定每个副本中哪些行是正确的,所以它要求你解决它们。

行:

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

主文件中文件副本中出现的内容。

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

分支新功能

你应该只需要编辑文件,就像你希望它最终出现一样。然后...

git add .gitignore
git commit

答案 1 :(得分:6)

只需编辑.gitignore文件即可解决冲突:

<强>之前

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

<强>后

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

然后:

git add .gitignore

git commit

自动生成的提交消息应该是apear,接受它(save&amp; close)并且已经完成。

答案 2 :(得分:2)

发生的事情是合并冲突:两个分支在不同的流中同时更改了文件&#34;#34;。您可以看到其他分支在&#34; newfeature&#34;中所做的更改。部分和另一部分在HEAD部分。

您需要做的是编辑该文件,使其包含您想要的内容,添加要遵循的内容然后提交。这称为合并提交。

现在,我上面讲的是手工合并,&#34;手动&#34;。这可能是最容易理解的。您也可以使用git mergetool命令使用可视化工具(如果已配置)执行此操作,或使用&#34; git merge&#34;有一些策略会告诉它如何处理冲突。

答案 3 :(得分:1)

使用git mergetool来解决冲突(或者只是手动修复它;这不是一个特别难以解决的问题),然后重新提交。

答案 4 :(得分:1)

修复.gitignore文件中的冲突,添加更新后的版本,然后提交:

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

答案 5 :(得分:1)

您应该手动合并.gitignore,然后通过

将其添加到索引中
$ git add .gitignore

您可以在此处获取合并的基础知识: http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging

答案 6 :(得分:1)

Git的自动合并失败。当尝试合并分支/推送内容时,在不同分支/存储库中同时发生同一文件的更改时,通常会发生这种情况。

对分支newfeature上的.gitignore进行的修改与在master上进行的修改相混淆。 行:<<<<<<< HEAD表示在master上进行的修改,在此行之后,而行>>>>>>> newfeature表示对此行之前的newfeature所做的修改。这两个修改由=======分隔。

您应该手动编辑文件并保留/合并两个部分中的每个部分。然后你应该提交(删除<<<<HEAD=====>>>newfeature行后。