我的情况看起来像是一个 bug.... 使用 git 2.21.0
我进行了一次 pull... 它抱怨二进制文件:
warning: Cannot merge binary files: <path>
Auto-merging <path>
CONFLICT (content): Merge conflict in <path>
Automatic merge failed; fix conflicts and then commit the result.
然后,这里任何答案都没有产生任何有意义的输出。
如果我查看现在拥有的文件...它就是我编辑过的那个。如果我执行以下任一操作:
git checkout --theirs -- <path>
git checkout --ours -- <path>
我得到输出:
Updated 0 paths from the index
我仍然拥有文件的版本。如果我使用rm命令,然后再checkout,它会显示1,但仍然会给我我的文件版本。
git mergetool 命令如下:
No files need merging
而且 git 状态显示
All conflicts fixed but you are still merging.
(use "git commit" to conclude merge)
一种选择是撤销提交...但我很不幸,我有很多次提交,而这个坏的提交是第一个。我不想浪费时间重复这个过程。
所以为了解决这个疯狂的问题:
我只需要运行
git commit
这会导致丢失远程版本,并浪费一些空间来存储额外的二进制文件...
git checkout <commit where the remote version exists> <path>
这会让我拿回远程版本。
然后再次编辑文件... 然后提交和推送,这可能意味着浪费空间存储二进制文件的另一个副本。
git checkout --ours <path>
命令后,我收到了Updated 0 paths from the index
的提示。我用git add <path>
命令解决了这个问题,它的作用是相同的。 - Andriy