猿问

如何修复GIT错误:目标文件为空?

当我尝试提交更改时,出现以下错误:


error: object file .git/objects/31/65329bb680e30595f242b7c4d8406ca63eeab0 is empty

fatal: loose object 3165329bb680e30595f242b7c4d8406ca63eeab0 (stored in .git/objects/31/65329bb680e30595f242b7c4d8406ca63eeab0) is corrupt

任何想法如何解决此错误?


编辑


我试过git fsck了


error: object file .git/objects/03/dfd60a4809a3ba7023cbf098eb322d08630b71 is empty

fatal: loose object 03dfd60a4809a3ba7023cbf098eb322d08630b71 (stored in .git/objects/03/dfd60a4809a3ba7023cbf098eb322d08630b71) is corrupt


四季花海
浏览 2544回答 3
3回答

杨__羊羊

我有一个类似的问题。我的笔记本电脑在git操作期间电量耗尽。嘘。我没有任何备份。(注意,Ubuntu One不是git的备份解决方案;它将用损坏的存储库有帮助地覆盖您的健全存储库。)对于git向导,如果这是修复它的不好方法,请发表评论。但是,它确实为我工作了……至少是暂时的。第1步:备份.git(实际上,我在更改某些步骤的每一步之间进行此操作,但是使用新的复制到名称,例如.git-old-1,.git-old-2等) :cp -a .git .git-old步骤2:执行 git fsck --fullnathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git fsck --fullerror: object file .git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e is emptyfatal: loose object 8b61d0135d3195966b443f6c73fb68466264c68e (stored in .git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e) is corrupt步骤3:删除空文件。我想通了。反正还是空白。nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ rm .git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e&nbsp;rm: remove write-protected regular empty file `.git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e'? y步骤3:git fsck再次运行。继续删除空文件。您还可以cd进入.git目录并运行find . -type f -empty -delete -print以删除所有空文件。最终git开始告诉我它实际上是在处理对象目录:nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git fsck --fullChecking object directories: 100% (256/256), done.error: object file .git/objects/e0/cbccee33aea970f4887194047141f79a363636 is emptyfatal: loose object e0cbccee33aea970f4887194047141f79a363636 (stored in .git/objects/e0/cbccee33aea970f4887194047141f79a363636) is corrupt步骤4:删除所有空文件后,我最终开始git fsck实际运行:nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git fsck --fullChecking object directories: 100% (256/256), done.error: HEAD: invalid sha1 pointer af9fc0c5939eee40f6be2ed66381d74ec2be895ferror: refs/heads/master does not point to a valid object!error: refs/heads/master.u1conflict does not point to a valid object!error: 0e31469d372551bb2f51a186fa32795e39f94d5c: invalid sha1 pointer in cache-treedangling blob 03511c9868b5dbac4ef1343956776ac508c7c2a2missing blob 8b61d0135d3195966b443f6c73fb68466264c68emissing blob e89896b1282fbae6cf046bf21b62dd275aaa32f4dangling blob dd09f7f1f033632b7ef90876d6802f5b5fede79amissing blob caab8e3d18f2b8c8947f79af7885cdeeeae192fdmissing blob e4cf65ddf80338d50ecd4abcf1caf1de3127c229步骤5:尝试git reflog。失败,因为我的头坏了。nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git reflogfatal: bad object HEAD步骤6:Google。找到这个。手动获取reflog的最后两行:nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ tail -n 2 .git/logs/refs/heads/masterf2d4c4868ec7719317a8fce9dc18c4f2e00ede04 9f0abf890b113a287e10d56b66dbab66adc1662d Nathan VanHoudnos <nathanvan@gmail.com> 1347306977 -0400&nbsp; commit: up to p. 24, including correcting spelling of my name9f0abf890b113a287e10d56b66dbab66adc1662d af9fc0c5939eee40f6be2ed66381d74ec2be895f Nathan VanHoudnos <nathanvan@gmail.com> 1347358589 -0400&nbsp; commit: fixed up to page 28步骤7:请注意,从步骤6中我们了解到HEAD当前指向最后的提交。因此,让我们尝试仅查看父提交:nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git show 9f0abf890b113a287e10d56b66dbab66adc1662dcommit 9f0abf890b113a287e10d56b66dbab66adc1662dAuthor: Nathan VanHoudnos <nathanvan@XXXXXX>Date:&nbsp; &nbsp;Mon Sep 10 15:56:17 2012 -0400&nbsp; &nbsp; up to p. 24, including correcting spelling of my namediff --git a/tex/MCMC-in-IRT.tex b/tex/MCMC-in-IRT.texindex 86e67a1..b860686 100644--- a/tex/MCMC-in-IRT.tex+++ b/tex/MCMC-in-IRT.tex有效!步骤8:所以现在我们需要将HEAD指向9f0abf890b113a287e10d56b66dbab66adc1662d。nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git update-ref HEAD 9f0abf890b113a287e10d56b66dbab66adc1662d哪个没抱怨。步骤9:看看fsck怎么说:nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git fsck --fullChecking object directories: 100% (256/256), done.error: refs/heads/master.u1conflict does not point to a valid object!error: 0e31469d372551bb2f51a186fa32795e39f94d5c: invalid sha1 pointer in cache-treedangling blob 03511c9868b5dbac4ef1343956776ac508c7c2a2missing blob 8b61d0135d3195966b443f6c73fb68466264c68emissing blob e89896b1282fbae6cf046bf21b62dd275aaa32f4dangling blob dd09f7f1f033632b7ef90876d6802f5b5fede79amissing blob caab8e3d18f2b8c8947f79af7885cdeeeae192fdmissing blob e4cf65ddf80338d50ecd4abcf1caf1de3127c229步骤10:高速缓存树中的无效sha1指针似乎来自于(现已过时)索引文件(source)。所以我杀了它并重置了仓库。nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ rm .git/indexnathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git resetUnstaged changes after reset:M&nbsp; &nbsp;tex/MCMC-in-IRT.texM&nbsp; &nbsp;tex/recipe-example/build-example-plots.RM&nbsp; &nbsp;tex/recipe-example/build-failure-plots.R步骤11:再次查看fsck ...nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git fsck --fullChecking object directories: 100% (256/256), done.error: refs/heads/master.u1conflict does not point to a valid object!dangling blob 03511c9868b5dbac4ef1343956776ac508c7c2a2dangling blob dd09f7f1f033632b7ef90876d6802f5b5fede79a在晃来晃去斑点不是错误。我不关心master.u1冲突,现在它可以正常工作了,我不想再碰它了!第12步:掌握本地编辑信息:nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git status# On branch master# Changes not staged for commit:#&nbsp; &nbsp;(use "git add <file>..." to update what will be committed)#&nbsp; &nbsp;(use "git checkout -- <file>..." to discard changes in working directory)##&nbsp; &nbsp;modified:&nbsp; &nbsp;tex/MCMC-in-IRT.tex#&nbsp; &nbsp;modified:&nbsp; &nbsp;tex/recipe-example/build-example-plots.R#&nbsp; &nbsp;modified:&nbsp; &nbsp;tex/recipe-example/build-failure-plots.R#< ... snip ... >no changes added to commit (use "git add" and/or "git commit -a")nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git commit -a -m "recovering from the git fiasco"[master 7922876] recovering from the git fiasco&nbsp;3 files changed, 12 insertions(+), 94 deletions(-)nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git add tex/sept2012_code/example-code-testing.Rnathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git commit -a -m "adding in the example code"[master 385c023] adding in the example code&nbsp;1 file changed, 331 insertions(+)&nbsp;create mode 100644 tex/sept2012_code/example-code-testing.R因此,希望将来对人们有用。我很高兴它奏效。

幕布斯7119047

git对象文件已损坏(也如其他答案所指出)。这可能在机器崩溃等情况下发生。我有同样的事情。在阅读了其他顶级答案之后,我发现了使用以下命令修复损坏的git存储库的最快方法(在包含该.git文件夹的git工作目录中执行):(确保首先备份您的git仓库文件夹!)find .git/objects/ -type f -empty | xargs rmgit fetch -pgit fsck --full这将首先删除所有导致整个存储库损坏的空对象文件,然后从远程存储库中获取丢失的对象(以及最新更改),然后进行完整的对象存储检查。在这一点上,应该可以成功执行而不会出现任何错误(尽管可能还会有一些警告!)PS。这个答案表明您在某个地方(例如,在GitHub上)有一个git存储库的远程副本,而损坏的存储库是与仍处于正常状态的远程存储库绑定的本地存储库。如果不是这种情况,请不要尝试按照我的建议进行修复。

小怪兽爱吃肉

解决了此问题,删除了git fsck检测到的各种空文件,然后运行简单的git pull。我感到失望的是,即使文件系统也实现了日记功能和其他“事务性”技术来保持fs的正常运行,由于电源故障或设备空间不足,git可能会陷入损坏状态(并且无法自行恢复)。
随时随地看视频慕课网APP
我要回答