【问题标题】:Merging Issues with Git用 Git 合并问题
【发布时间】:2012-07-16 15:27:40
【问题描述】:

我正在使用git version 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'.

如何解决这些错误?

【问题讨论】:

  • 所以当你在 Github 上创建一个 repo 并选中 Initialize this repository with a README 选项时会发生这种情况。因此,最简单的解决方案是不检查该选项。 Else 从 Github 克隆远程仓库,而不是在本地机器上创建新仓库。 Else 按照错误消息的说明进行操作,它也会为您找到解决方案。 :)
  • 那么,运气好吗?如果您接受其中一个答案,请将其标记为接受。
  • CodeGnome,“我是 git 新手”有什么不清楚的地方?
  • 该错误消息的显示现在在 git 2.1(2014 年 8 月)中发生了变化。见my answer below

标签: git github git-commit git-pull


【解决方案1】:

这样做:

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

现在将 README.md 文件的内容替换为您想要的内容。如果您根本不想要它,请执行 git rm README.md

如果你替换了内容,提交并推送这些内容:

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

【讨论】:

  • git merge --abort 然后git pull 然后git prune。我运行了这些命令,一切都解决了
  • nice ++ 之后 git pull origin master --allow-unrelated-histories
【解决方案2】:

试试:

 git reset README.md

我有一个类似的问题,这是唯一解决它的方法。

【讨论】:

  • 这是唯一对我有用的解决方案。我只是厌倦了mergetool,而事实上我已经做了一个单行更改。 (尽管有多少次,我选择让 mergetool 知道我的选择(B),它从未将其标记为已解决)
【解决方案3】:

虽然git reset 是一个很好的解决方案,但请注意警告消息现在具有更好的格式(Git 2.1,2014 年 8 月)

commit d795216commit c057b24Jeff King (peff)

不规则的换行使阅读起来很尴尬,而且占用的行数超出了必要的范围。相反,让我们将其重新包装为每行大约 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.

【讨论】:

    【解决方案4】:

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

    【讨论】:

      猜你喜欢
      • 2015-10-07
      • 2012-01-18
      • 2021-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-15
      • 2018-10-10
      相关资源
      最近更新 更多