使用Git合并问题

34

我正在使用 git 版本 1.7.11.msysgit.0

我在 GitHUB 上创建了一个仓库,并添加了一个名为 README.md 的文件,其中包含一些文本内容。

稍后,我安装了 GIT 客户端,通过克隆将服务器内容获取到我的计算机上。

然后我在本地计算机上删除了 README.md 文件。

现在当我执行 git commit 命令时,会出现以下错误:

praveenk@MSIN-BT-100 /d/workspace/MYTestRepo (master|MERGING)
$ git commit ;
U       README.md
error: 'commit' is not possible because you have unmerged files.
hint: Fix them up in the work tree,
hint: and then use 'git add/rm <file>' as
hint: appropriate to mark resolution and make a commit,
hint: or use 'git commit -a'.
fatal: Exiting because of an unresolved conflict.

这是使用git pull命令的效果:

$ git pull;
U       README.md
A       One.txt
Pull 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, or use 'git commit -a'.

如何解决这些错误?


1
当你在Github上创建一个仓库并勾选“使用README初始化此存储库”选项时,就会出现这种情况。因此,最简单的解决方案是不要勾选该选项。否则,从Github克隆远程仓库而不是在本地机器上创建新仓库。或者按照错误消息所说的去做,它也会为你找到解决方案。 :) - uday
那么,有什么进展吗?如果你接受了其中一个答案,请标记一下。 - F. Orvalho
1
CodeGnome,"我是Git新手"有什么不清楚的地方? - thumbtackthief
该错误信息的呈现方式在git 2.1(2014年8月)中已经改变。请参见下面的我的回答 - VonC
4个回答

44

做这个:

git merge --abort
git pull (to be sure you're up-to-date)

现在用你想要的文本替换README.md文件的内容。如果你不想要它,使用git rm README.md命令。

如果你更改了README.md文件的内容,就使用以下命令将其提交和推送:

git add README.md
git commit -m "comment"
git push

1
git merge --abort 然后 git pull 再执行 git prune。我运行了这些命令,一切都解决了。 - Brandon
不错++之后,执行git pull origin master --allow-unrelated-histories - Hamit YILDIRIM

12

尝试:

 git reset README.md

我遇到了类似的问题,而这是唯一解决它的方法。


这是唯一对我有效的解决方案。实际上,我只是因为进行了单行更改而厌倦了合并工具。(尽管我选择让合并工具知道我的选择(B)的次数很多,但它从未将其标记为已解决) - Mahesh

3
虽然 git reset 是一个好的解决方案,但请注意警告消息现在有更好的格式(Git 2.1,2014 年 8 月)。
请参见由 Jeff King (peff) 提交的 提交 d795216提交 c057b24
不规则的换行使阅读很麻烦,并且占用了比必要更多的行。相反,让我们将其重新包装为每行约 60 个字符。 引号周围的 "commit" 很笨拙;用户不关心此消息是填充了命令名称的模板。
$ git commit
U       foo
error: commit is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit, or use
hint: 'git commit -a'.
fatal: Exiting because of an unresolved conflict.

-1

即使将图像的显示属性设置为none,浏览器仍会请求图像。 为了防止这种情况发生,您可以实现我之前提到的解决方案,但如果您要频繁切换图像的可见性,则在HTML中添加和删除图像可能是不必要的性能成本,您可以通过使用display:none属性来避免。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接