解决git错误: error object file is empty , The remote end hung up unexpectedly

今天执行git pull时遇到麻烦,应该是昨天电脑异常关机造成的git数据损坏:

$git pull
error: object file .git/objects/88/526655aa4eca14ead2d443e80082276a79e0c2 is empty
error: object file .git/objects/88/526655aa4eca14ead2d443e80082276a79e0c2 is empty
fatal: loose object 88526655aa4eca14ead2d443e80082276a79e0c2 (stored in .git/objects/88/526655aa4eca14ead2d443e80082276a79e0c2) is corrupt
fatal: The remote end hung up unexpectedly

这种情况以前也偶尔遇到过,我当时的解决办法又笨又简单,就是删除当前代码重新从远程仓库下载一份代码,反正只要确保远程仓库是最新完整的代码就没问题。
这次不同了,本地有不少花时间生成的中间结果代码,删除之后重建要花时间,所以就不想用这么笨的办法。
在stackoverflow上找到这篇文章《how to fix GIT error: object file is empty?》,几个answer提供了不同的解决方式,第一种方法,好烦好复杂,看不下去,后来发现国内不少翻译这篇文章的帖子,介绍的就是第一种方法。

而第二个answer提供的方法就简单明白许多,过程就三步:

解决git错误: error object file is empty , The remote end hung up unexpectedly_第1张图片

于是尝试用这个办法:

step1:
删除所有因为数据损坏导致的空对象文件(remove any empty object files)。执行第一步没有任何输出

$ find .git/objects/ -type f -empty | xargs rm

step2:
下载上一步删除的对象文件(fetch down the missing objects)

$ git fetch -p
error: refs/heads/master does not point to a valid object!
error: refs/remotes/origin/master does not point to a valid object!
error: refs/heads/master does not point to a valid object!
error: refs/remotes/origin/master does not point to a valid object!
error: refs/heads/master does not point to a valid object!
error: refs/remotes/origin/master does not point to a valid object!
error: refs/heads/master does not point to a valid object!
error: refs/remotes/origin/master does not point to a valid object!
error: refs/heads/master does not point to a valid object!
error: refs/remotes/origin/master does not point to a valid object!
remote: Counting objects: 118, done.
remote: Compressing objects: 100% (113/113), done.
remote: Total 118 (delta 92), reused 0 (delta 0)
Receiving objects: 100% (118/118), 15.90 KiB | 0 bytes/s, done.
Resolving deltas: 100% (92/92), completed with 26 local objects.
From https://gitee.com/l0km/app
 * [new branch]      master     -> origin/master

step3:
做一次全面的存储对象检查(do a full object store check)

$ git fsck --full
Checking object directories: 100% (256/256), done.
Checking objects: 100% (6619/6619), done.
dangling commit 18086406efd2c3e37dc478744304dd2a758206bb
dangling blob 760bbd43e62054478eb3edbffd88ea65adb3f094
dangling commit fcc10548cc0d06de24b2903cf3ec745bb78185cb
dangling blob 234ff40df2a81d1a2625aae8ef76f6c7c92dc5f6
dangling blob 38e25f663bff5ebec04fa559500860e90fd4bf23
dangling commit 406f700c73b3a263604fea2a464634b389153835
dangling commit bcfcb27bfdb5d54b80557a9723bcbcab6b601a90

三步完成之后,再次执行git pull,错误消失,成功。

$ git pull
Updating 8852665..f66f1dd
Fast-forward
 CMakeLists.txt                                 |  4 +--
 dependencies/build_mgncs.sh                    |  1 +
 dependencies/cmake/Modules/FindLIBCONFIG.cmake |  4 ++-
 dependencies/cmake/Modules/FindMGNCS.cmake     |  2 +-
 dependencies/cmake/Modules/FindMGPLUS.cmake    |  2 +-
 dependencies/cmake/Modules/FindMGUTILS.cmake   |  2 +-
 dependencies/cmake/Modules/FindMINIGUI.cmake   |  2 +-
 dependencies/cmake/Modules/depcommon.cmake     | 22 +++++++-----
 dependencies/mips_build_mgncs.sh               | 47 +++++++++++++-------------
 facelock/CMakeLists.txt                        |  6 +++-
 10 files changed, 52 insertions(+), 40 deletions(-)

你可能感兴趣的:(开发工具)