当前位置: 首页 > 工具软件 > git-lfs-one > 使用案例 >

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

诸嘉澍
2023-12-01

本文翻译自:how to fix GIT error: object file is empty?

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: 我尝试了git fsck

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

#1楼

参考:https://stackoom.com/question/n7Jv/如何修复GIT错误-目标文件为空


#2楼

I had a similar problem. 我有一个类似的问题。 My laptop ran out of battery during a git operation. 我的笔记本电脑在git操作期间电量耗尽。 Boo.

I didn't have any backups. 我没有任何备份。 (NB Ubuntu One is not a backup solution for git; it will helpfully overwrite your sane repository with your corrupted one.) (注意,Ubuntu One不是git的备份解决方案;它将用损​​坏的存储库有帮助地覆盖您的健全存储库。)

To the git wizards, if this was a bad way to fix it, please leave a comment. 对于git向导,如果这是修复它的不好方法,请发表评论。 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, eg .git-old-1, .git-old-2, etc.): 第1步:备份.git(实际上,我在更改某些步骤的每一步之间进行此操作,但是使用新的复制到名称,例如.git-old-1,.git-old-2等) :

cp -a .git .git-old

Step 2: Run git fsck --full 步骤2:运行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. 步骤3:删除空文件。 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. 步骤3:再次运行git fsck Continue deleting the empty files. 继续删除空文件。 You can also cd into the .git directory and run find . -type f -empty -delete -print 您也可以cd进入.git目录并运行find . -type f -empty -delete -print find . -type f -empty -delete -print to remove all empty files. find . -type f -empty -delete -print删除所有空文件。 Eventually git started telling me it was actually doing something with the object directories: 最终git开始告诉我它实际上是在处理对象目录:

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: 步骤4:删除所有空文件后,我最终来到git fsck实际运行中:

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 . 步骤5:尝试git reflog Fail because my HEAD is broken. 失败,因为我的头坏了。

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

Step 6: Google. 步骤6:Google。 Find this . 找到这个 Manually get the last two lines of the reflog: 手动获取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. 步骤7:请注意,从步骤6中我们了解到HEAD当前指向最后的提交。 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. 步骤8:所以现在我们需要将HEAD指向9f0abf890b113a287e10d56b66dbab66adc1662d。

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

Which didn't complain. 哪个没抱怨。

Step 9: See what fsck says: 步骤9:看看fsck怎么说:

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 ). 步骤10:高速缓存树中的无效sha1指针似乎来自于(现已过时)索引文件( 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... 步骤11:再次查看fsck ...

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! 我不关心master.u1冲突,现在它可以正常工作了,我不想再碰它了!

Step 12: Catching up with my local edits: 第12步:掌握本地编辑信息:

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. 我很高兴它奏效。


#3楼

I just had the same issue : after pulling the distant repository, when I did a git status I got : "error: object file (...) is empty" "fatal: loose object (...) is corrupted" 我只是遇到了同样的问题:拉远的存储库后,当我进行git状态时,我得到:“错误:对象文件(...)为空”“致命:松散的对象(...)已损坏”

The way I resolved this was to : 我解决此问题的方法是:

  1. git stash git stash
  2. removing git file in error (not sure that is necessary) 错误删除git文件(不确定是否有必要)
  3. git stash clear git隐藏

I dont know exactly what things happened, but that instructions seemed to make everything clean. 我不知道到底发生了什么,但是那条指示似乎使一切都变得干净了。


#4楼

Copy everything (in the folder containing the .git) to a backup, then delete everything and restart. 将所有内容(包含.git的文件夹中)复制到备份中,然后删除所有内容并重新启动。 Make sure you have the git remote handy: 确保您拥有方便的git remote:

git remote -v
 origin git@github.com:rwldrn/idiomatic.js.git (fetch)
 origin git@github.com:rwldrn/idiomatic.js.git (push)

Then 然后

mkdir mygitfolder.backup
cp mygitfolder/* mygitfolder.backup/
cd mygitfolder
rm -r * .git*
git init
git remote add origin git@github.com:rwldrn/idiomatic.js.git

Then merge any new files manually, and try to keep your computer turned on. 然后手动合并所有新文件,并尝试保持计算机电源打开。


#5楼

I solved this removing the various empty files that git fsck was detecting, and then running a simple git pull. 我解决了此问题,删除了git fsck检测到的各种空文件,然后运行简单的git pull。

I find it disappointing that now that even filesystems implement journaling and other "transactional" techniques to keep the fs sane, git can get to a corrupted state (and not be able to recover by itself) because of a power failure or space on device. 我感到失望的是,即使文件系统也实现了日记功能和其他“事务性”技术来保持fs健全,由于电源故障或设备空间不足,git可能会进入损坏状态(并且无法自行恢复)。


#6楼

  1. mv your folder app to make backup, ie mv app_folder app_folder_bk (it is like a git stash ) mv您的文件夹应用进行备份,即mv app_folder app_folder_bk(就像git stash一样
  2. git clone your_repository git clone your_repository
  3. Finally,. 最后,。 Open a merge tool (I use meld diff viewer linux or Winmerge Windows) and copy the changes from right( app_folder_bk ) to left( new app_folder ) (it is like a git stash apply ). 打开一个合并工具(我使用diff diff查看器linux或Winmerge Windows),然后将更改从右( app_folder_bk )复制到左(new app_folder )(就像git stash apply一样 )。

That's all. 就这样。 Maybe it is not the best way, but I think it is so practical . 也许这不是最好的方法,但我认为它是如此实用。

 类似资料: