如何修复GIT错误:目标文件是空的? [英] how to fix GIT error: object file is empty?

查看:196
本文介绍了如何修复GIT错误:目标文件是空的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 错误:object file .git / objects / 31 / 65329bb680e30595f242b7c4d8406ca63eeab0为空
致命:松散对象3165329bb680e30595f242b7c4d8406ca63eeab0(存储在.git / objects / 31 / 65329bb680e30595f242b7c4d8406ca63eeab0中)已损坏

任何想法如何解决这个错误?

编辑



我试过 git fsck 我有:

 错误:object file .git / objects / 03 / dfd60a4809a3ba7023cbf098eb322d08630b71为空
致命:松散对象03dfd60a4809a3ba7023cbf098eb322d08630b71(存储在.git / objects / 03 / dfd60a4809a3ba7023cbf098eb322d08630b71中)已损坏


解决方案

我有类似的问题。我的笔记本电脑在git操作过程中电池耗尽。嘘。



我没有任何备份。 (NB Ubuntu One不是git的备份解决方案;它会帮助你用你的损坏的仓库覆盖你的仓库。)



对于git向导,如果这是一个糟糕的如何修复它,请留下评论。但是,它确实为我工作......至少是暂时的。步骤1:做一个.git的备份(事实上,我在每一步改变内容的时候都会这样做,但是使用新的副本名称,例如.git -old-1,.git-old-2等):

  cp -a .git .git-old 

第二步:运行 git fsck --full



pre $ nathanvan @ nathanvan-N61Jq:〜/ workspace / mcmc-chapter $ git fsck --full
error:object文件.git / objects / 8b / 61d0135d3195966b443f6c73fb68466264c68e为空
致命:松散对象8b61d0135d3195966b443f6c73fb68466264c68e(存储在.git / objects / 8b / 61d0135d3195966b443f6c73fb68466264c68e中)已损坏

第3步:删除空文件。我想到了什么;无论如何它的空白。

  nathanvan @ nathanvan-N61Jq:〜/工作区/ MCMC-章$ RM的.git /对象/ 8B / 61d0135d3195966b443f6c73fb68466264c68e 
rm:删除写保护的常规空文件`.git / objects / 8b / 61d0135d3195966b443f6c73fb68466264c68e'? y

第3步:再次运行 git fsck 。继续删除空文件。您也可以在 .git 目录下运行 cd 并运行 find。 -type f -empty -delete -print 删除所有空文件。最终git开始告诉我它实际上正在做一些对象目录:

pre $ nathanvan-N61Jq:〜/ workspace / mcmc -chapter $ git fsck --full
检查对象目录:100%(256/256),完成。
错误:目标文件.git / objects / e0 / cbccee33aea970f4887194047141f79a363636为空
致命:松散对象e0cbccee33aea970f4887194047141f79a363636(存储在.git / objects / e0 / cbccee33aea970f4887194047141f79a363636中)已损坏
git fsck $ b>实际运行:

pre $ nathanvan @ nathanvan-N61Jq:〜/ workspace / mcmc-chapter $ git fsck --full
检查对象目录:100%(256/256),完成。
错误:HEAD:无效的sha1指针af9fc0c5939eee40f6be2ed66381d74ec2be895f
错误:refs / heads / master没有指向有效的对象!
错误:refs / heads / master.u1conflict不指向有效的对象!
错误:0e31469d372551bb2f51a186fa32795e39f94d5c:在缓存树
无效SHA1指针晃来晃去的blob 03511c9868b5dbac4ef1343956776ac508c7c2a2
丢失一滴8b61d0135d3195966b443f6c73fb68466264c68e
丢失一滴e89896b1282fbae6cf046bf21b62dd275aaa32f4
晃来晃去的blob dd09f7f1f033632b7ef90876d6802f5b5fede79a
丢失一滴caab8e3d18f2b8c8947f79af7885cdeeeae192fd
缺少blob e4cf65ddf80338d50ecd4abcf1caf1de3127c229

第5步:尝试 git reflog 。因为我的HEAD坏了而失败。

  nathanvan @ nathanvan-N61Jq:〜/ workspace / mcmc-chapter $ git reflog 
致命错误:HEAD

第6步:Google。找到。手动获取引用日志的最后两行:

  nathanvan @ nathanvan-N61Jq:〜/ workspace / mcmc-chapter $ tail  - N 2的.git /日志/参/头/主
f2d4c4868ec7719317a8fce9dc18c4f2e00ede04 9f0abf890b113a287e10d56b66dbab66adc1662d森VanHoudnos< nathanvan@gmail.com> 1347306977 -0400承诺:最多p。 24,包括纠正我的名字
9f0abf890b113a287e10d56b66dbab66adc1662d af9fc0c5939eee40f6be2ed66381d74ec2be895f弥敦道VanHoudnos<的拼写; nathanvan@gmail.com> 1347358589 -0400 commit:固定到第28页

步骤7:请注意,从步骤6我们了解到HEAD目前正指向最后一次提交。所以,我们来看看父提交:

pre $ code> nathanvan @ nathanvan-N61Jq:〜/ workspace / mcmc-chapter $ git显示9f0abf890b113a287e10d56b66dbab66adc1662d
提交9f0abf890b113a287e10d56b66dbab66adc1662d
的作者:森VanHoudnos< nathanvan @ XXXXXX>
日期:星期一9月10日15:56:17 2012 -0400

至第p页。 24,包括更正我名字的拼写。

diff --git a / tex / MCMC-in-IRT.tex b / tex / MCMC-in-IRT.tex
index 86e67a1 .. b860686 100644
--- a / tex / MCMC-in-IRT.tex
+++ b / tex / MCMC-in-IRT.tex

它有效!

第8步:现在我们需要将HEAD指向9f0abf890b113a287e10d56b66dbab66adc1662d。

  nathanvan @ nathanvan-N61Jq:〜/工作区/ MCMC-章$ GIT中更新-REF HEAD 9f0abf890b113a287e10d56b66dbab66adc1662d 

其中没有抱怨。



第9步:查看fsck说:

  nathanvan @ nathanvan-N61Jq:〜/ workspace / mcmc-chapter $ git fsck --full 
检查对象目录:100%(256/256),完成。
错误:refs / heads / master.u1conflict不指向有效的对象!
错误:0e31469d372551bb2f51a186fa32795e39f94d5c:在缓存树
无效SHA1指针晃来晃去的blob 03511c9868b5dbac4ef1343956776ac508c7c2a2
丢失一滴8b61d0135d3195966b443f6c73fb68466264c68e
丢失一滴e89896b1282fbae6cf046bf21b62dd275aaa32f4
晃来晃去的blob dd09f7f1f033632b7ef90876d6802f5b5fede79a
丢失一滴caab8e3d18f2b8c8947f79af7885cdeeeae192fd
丢失blob e4cf65ddf80338d50ecd4abcf1caf1de3127c229

第10步:缓存树中的无效sha1指针看起来像它来自(目前已过时的)索引文件()。所以我杀了它,并重置回购。

  nathanvan @ nathanvan-N61Jq:〜/ workspace / mcmc-chapter $ rm .git / index 
nathanvan @ nathanvan-N61Jq:〜/ workspace / mcmc-chapter $ git reset
复位后的不间断更改:
M tex / MCMC-in-IRT.tex
M tex / recipe-example / build-example-plots.R
M tex / recipe-example / build-failure-plots.R

第11步:再次查看fsck ...

  nathanvan @ nathanvan-N61Jq :〜/ workspace / mcmc-chapter $ git fsck --full 
检查对象目录:100%(256/256),done。
错误:refs / heads / master.u1conflict不指向有效的对象!
dangling blob 03511c9868b5dbac4ef1343956776ac508c7c2a2
dangling blob dd09f7f1f033632b7ef90876d6802f5b5fede79a

晃来晃去的斑点不是错误。我不关心master.u1冲突,现在它正在工作,我不想再碰它了!



第12步:赶上我的本地编辑:

  nathanvan @ nathanvan-N61Jq:〜/ workspace / mcmc-chapter $ git status 
#在分支主机上
#没有为commit提交更改:
#(使用git add< file> .. 。以更新将提交的内容)
#(使用git checkout - < file> ...放弃工作目录中的更改)

#modified:tex / MCMC in-IRT.tex
#modified:tex / recipe-example / build-example-plots.R
#modified:tex / recipe-example / build-failure-plots.R

< ... snip ...>
没有更改添加到提交(使用git add和/或git commit -a)


nathanvan @ nathanvan-N61Jq:〜/ workspace / mcmc-chapter $ g $ commit -a -m从git失败中恢复
[master 7922876]从git失败恢复
更改了3个文件,12个插入(+),94个删除( - )

nathanvan @ nathanvan-N61Jq:〜/ workspace / mcmc-chapter $ git add tex / sept2012_code / example-code-testing.R
nathanvan @ nathanvan-N61Jq:〜/ workspace / mcmc-chapter $ git提交-a -m添加示例代码
[master 385c023]在示例代码中添加
1个文件已更改,331个插入(+)
创建模式100644 tex / sept2012_code / example -code-testing.R

所以希望这对将来的用户有一定的用处。我很高兴它的工作。


When I try to commit changes, I get this error:

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

Any idea how to solve this error ?

EDIT

I tried git fsck I've got:

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

解决方案

I had a similar problem. My laptop ran out of battery during a git operation. Boo.

I didn't have any backups. (N.B. Ubuntu One is not a backup solution for git; it will helpfully overwrite your sane repository with your corrupted one.)

To the git wizards, if this was a bad way to fix it, please leave a comment. It did, however, work for me... at least temporarily.

Step 1: Make a backup of .git (in fact I do this in between every step that changes something, but with a new copy-to name, e.g. .git-old-1, .git-old-2, etc.):

cp -a .git .git-old

Step 2: Run git fsck --full

nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git fsck --full
error: object file .git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e is empty
fatal: loose object 8b61d0135d3195966b443f6c73fb68466264c68e (stored in .git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e) is corrupt

Step 3: Remove the empty file. I figured what the heck; its blank anyway.

nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ rm .git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e 
rm: remove write-protected regular empty file `.git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e'? y

Step 3: Run git fsck again. Continue deleting the empty files. You can also cd into the .git directory and run find . -type f -empty -delete -print to remove all empty files. Eventually git started telling me it was actually doing something with the object directories:

nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git fsck --full
Checking object directories: 100% (256/256), done.
error: object file .git/objects/e0/cbccee33aea970f4887194047141f79a363636 is empty
fatal: loose object e0cbccee33aea970f4887194047141f79a363636 (stored in .git/objects/e0/cbccee33aea970f4887194047141f79a363636) is corrupt

Step 4: After deleting all of the empty files, I eventually came to git fsck actually running:

nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git fsck --full
Checking object directories: 100% (256/256), done.
error: HEAD: invalid sha1 pointer af9fc0c5939eee40f6be2ed66381d74ec2be895f
error: 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-tree
dangling blob 03511c9868b5dbac4ef1343956776ac508c7c2a2
missing blob 8b61d0135d3195966b443f6c73fb68466264c68e
missing blob e89896b1282fbae6cf046bf21b62dd275aaa32f4
dangling blob dd09f7f1f033632b7ef90876d6802f5b5fede79a
missing blob caab8e3d18f2b8c8947f79af7885cdeeeae192fd
missing blob e4cf65ddf80338d50ecd4abcf1caf1de3127c229

Step 5: Try git reflog. Fail because my HEAD is broken.

nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git reflog
fatal: bad object HEAD

Step 6: Google. Find this. Manually get the last two lines of the reflog:

nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ tail -n 2 .git/logs/refs/heads/master
f2d4c4868ec7719317a8fce9dc18c4f2e00ede04 9f0abf890b113a287e10d56b66dbab66adc1662d Nathan VanHoudnos <nathanvan@gmail.com> 1347306977 -0400  commit: up to p. 24, including correcting spelling of my name
9f0abf890b113a287e10d56b66dbab66adc1662d af9fc0c5939eee40f6be2ed66381d74ec2be895f Nathan VanHoudnos <nathanvan@gmail.com> 1347358589 -0400  commit: fixed up to page 28

Step 7: Note that from Step 6 we learned that the HEAD is currently pointing to the very last commit. So let's try to just look at the parent commit:

nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git show 9f0abf890b113a287e10d56b66dbab66adc1662d
commit 9f0abf890b113a287e10d56b66dbab66adc1662d
Author: Nathan VanHoudnos <nathanvan@XXXXXX>
Date:   Mon Sep 10 15:56:17 2012 -0400

    up to p. 24, including correcting spelling of my name

diff --git a/tex/MCMC-in-IRT.tex b/tex/MCMC-in-IRT.tex
index 86e67a1..b860686 100644
--- a/tex/MCMC-in-IRT.tex
+++ b/tex/MCMC-in-IRT.tex

It worked!

Step 8: So now we need to point HEAD to 9f0abf890b113a287e10d56b66dbab66adc1662d.

nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git update-ref HEAD 9f0abf890b113a287e10d56b66dbab66adc1662d

Which didn't complain.

Step 9: See what fsck says:

nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git fsck --full
Checking 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-tree
dangling blob 03511c9868b5dbac4ef1343956776ac508c7c2a2
missing blob 8b61d0135d3195966b443f6c73fb68466264c68e
missing blob e89896b1282fbae6cf046bf21b62dd275aaa32f4
dangling blob dd09f7f1f033632b7ef90876d6802f5b5fede79a
missing blob caab8e3d18f2b8c8947f79af7885cdeeeae192fd
missing blob e4cf65ddf80338d50ecd4abcf1caf1de3127c229

Step 10: The invalid sha1 pointer in cache-tree seemed like it was from a (now outdated) index file (source). So I killed it and reset the repo.

nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ rm .git/index
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git reset
Unstaged changes after reset:
M   tex/MCMC-in-IRT.tex
M   tex/recipe-example/build-example-plots.R
M   tex/recipe-example/build-failure-plots.R

Step 11: Looking at the fsck again...

nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git fsck --full
Checking object directories: 100% (256/256), done.
error: refs/heads/master.u1conflict does not point to a valid object!
dangling blob 03511c9868b5dbac4ef1343956776ac508c7c2a2
dangling blob dd09f7f1f033632b7ef90876d6802f5b5fede79a

The dangling blobs are not errors. I'm not concerned with master.u1conflict, and now that it is working I don't want to touch it anymore!

Step 12: Catching up with my local edits:

nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   tex/MCMC-in-IRT.tex
#   modified:   tex/recipe-example/build-example-plots.R
#   modified:   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
 3 files changed, 12 insertions(+), 94 deletions(-)

nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git add tex/sept2012_code/example-code-testing.R
nathanvan@nathanvan-N61Jq:~/workspace/mcmc-chapter$ git commit -a -m "adding in the example code"
[master 385c023] adding in the example code
 1 file changed, 331 insertions(+)
 create mode 100644 tex/sept2012_code/example-code-testing.R

So hopefully that can be of some use to people in the future. I'm glad it worked.

这篇关于如何修复GIT错误:目标文件是空的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆