1

可能重复:
无法与 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
4

1 回答 1

2

The error message from git say it all. You have un-merged changes between your two branches that need to be resolved before submitted the merge commit. Those merge conflicts happen because the file have been modified in the two branches.

To resolve this, you need to edit the files in conflict. For each file, you'll have to resolve the merge. The conflicts will be surrounded by <<<<<<<<<<<, =========== and >>>>>>>>>> markers. How you resolve them will depends on the changes (you may want to keep your changes, the changes in the remote branch or a combination of the two).

Once you've resolved all the conflicts, then you'll have to do git add for each file. And then git commit. The pre-filled commit message will indicate this is a merge commit and that there were some conflict resolved. You probably don't have to edit it unless your coding style mandate some particular formatting of your commit message.

So, to summarise, you'll have to do:

$ emacs GDCatalog/.classpath
... resolve conflict ...
$ git add GDCatalog/.classpath
... do the same for all other files ...
$ git commit
于 2013-01-05T11:54:17.103 回答