error: Pulling is not possible because you have unmerged files. hint: Fix them up in the work tree,

2 阅读1分钟

git pull error: Pulling is not possible because you have unmerged files. hint: Fix them up in the work tree, and then use 'git add/rm ' hint: as appropriate to mark resolution and make a commit. fatal: Exiting because of an unresolved conflict. 出现这个错误的原因是:Git 无法自动合并二进制文件(APK 文件)。 当您运行 git pull(这里实际上触发了 rebase)时,服务器上的最新代码和您本地那个“优化编译降低大小”的提交冲突了。因为 .apk 是二进制文件,Git 无法像文本文件那样进行对比合并,所以它暂停了 rebase,等待您手动选择保留哪一个版本。 目前您处于 Rebase 冲突挂起状态,所以再次运行 git pull 或直接 git checkout 都会报错。 针对这种情况,有两种解决方案。强烈推荐使用“方法 A”,对于二进制文件来说,这种方法最不易出错且干净。

方法 A:放弃冲突,强制同步服务器,然后手动替换(强烈推荐) 因为您是要“重新提交一次”,最稳妥的办法是让 Git 恢复到最干净的状态(和服务器完全一致),然后直接用您优化好的新 APK 覆盖它,重新做一次提交。 请按以下步骤操作:

  1. 终止当前的 rebase 状态

git rebase --abort (运行后,您的本地状态会回到 pull 之前。) 2. 将本地分支强制重置到服务器的最新状态

git reset --hard origin/master (这会清除您本地那个冲突的、已被 abandon 的本地 commit,让您的本地目录与服务器完全同步。)