如何解决git合并冲突?

时间:2013-01-05 10:57:19

标签: git

  

可能重复:
  Trouble merging with Git

我下载了一个git repo做了一些更改(删除了一些文件),然后提交了它。然后我做了git checkout -b“new branch”。在这里,我没有删除文件,但我确实做了一些更改并提交了它。现在我回到我的主分支并试图做一个git merge new_branch_i_created但是说:

fatal: 'merge' is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>' as
appropriate to mark resolution and make a commit, or use 'git commit -a'.

我做错了什么?

如果我尝试从我的主分支机构结账到新分支,它会说:

GDCatalog/.classpath: needs merge
GDCatalog/src/com/cyrilmottier/android/gdcatalog/CatalogActivity.java: needs merge
GDCatalog/src/com/cyrilmottier/android/gdcatalog/PagedViewActivity.java: needs merge
GreenDroid-GoogleAPIs/.classpath: needs merge
GreenDroid/.classpath: needs merge
GreenDroid/src/greendroid/widget/PagedView.java: needs merge
error: you need to resolve your current index first

1 个答案:

答案 0 :(得分:2)

来自git的错误消息说明了一切。在提交合并提交之前,您需要解析两个分支之间的未合并更改。发生这些合并冲突是因为文件已在两个分支中进行了修改。

要解决此问题,您需要编辑冲突的文件。对于每个文件,您必须解决合并。冲突将被<<<<<<<<<<<===========>>>>>>>>>>标记包围。您如何解决它们取决于更改(您可能希望保留更改,远程分支中的更改或两者的组合)。

解决所有冲突后,您必须为每个文件执行git add。然后git commit。预填充的提交消息将指示这是合并提交,并且已解决一些冲突。您可能不必编辑它,除非您的编码样式要求您提交消息的某些特定格式。

总而言之,你必须这样做:

$ emacs GDCatalog/.classpath
... resolve conflict ...
$ git add GDCatalog/.classpath
... do the same for all other files ...
$ git commit
相关问题