本文翻译自: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 -0400up to p. 24, including correcting spelling of my namediff --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 fiasco3 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 code1 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 -vorigin 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 . 也许这不是最好的方法,但我认为它是如此实用。

如何修复GIT错误:目标文件为空?相关推荐

  1. 如何修复无效的目标版本:Maven Build中的1.7、1.8、1.9或1.10错误

    如果您正在使用Maven构建Java项目,可能是在Eclipse中,或者是通过运行mvn install在命令提示符下构建的,并且构建失败并显示诸如"无效的目标发行版:1.7"或& ...

  2. git clone大文件EOF错误

    git clone大文件EOF错误 我们常用的git clone https://XXX 下载大文件时,加上墙的问题.会出现中断,例如gitlab git clone https://gitlab.c ...

  3. python判断一个文件夹里面是否为空_Python碎片化学习教程 @8. 判断目标文件夹是否为空...

    代码功能:判断目标文件夹是否为空 代码如下:import os  # 导入负责处理操作系统相关事务的os模块 tar_dir = "D:\\666"  # 指定目标文件夹 if l ...

  4. 解决使用git时候出现的“error pathspec ‘“xx文件“did not match any file(s) known to git”错误

    这次分享一个关于我在使用git时候出现的一个错误. 错误信息: error pathspec "xx文件" did not match any file(s) known to g ...

  5. 【BBED】BBED模拟并修复ORA-08102错误

    [BBED]BBED模拟并修复ORA-08102错误 1.1  BLOG文档结构图 1.2  前言部分 1.2.1  导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其 ...

  6. arcgis几何修复有作用吗_ArcGIS修复几何错误

    几何错误常存在于shapefile以及存储在个人地理数据库或文件地理数据库的要素类,而当数据不满足ArcGIS的规范时,就会遇到各种无响应和奔溃. 几何错误通常有:(查看原帮助文档) 1.短线段-有些 ...

  7. BBED模拟并修复ORA-08102错误

    1.3  本文简介 这几天一个朋友问我有关ORA-08102的错误,而且是关于OBJ$表上的I_OBJ4索引.这些系统对象的索引,不能采用重建或设置事件的方式来修复该错误.模模糊糊的记得很早以前看过使 ...

  8. Git 错误提交后该如何回滚操作

    1. Git 架构 Workspace:工作区(当前用户操作修改的区域) Index / Stage:暂存区 (add 后的区域) Repository:仓库区或本地仓库(commit 后的区域) R ...

  9. channelsftp 上传文件为空_SpringBoot文件上传下载篇(九)

    点击上方蓝色字体,关注我们 上传文件是互联网中应用的场景之一,最典型的情况就是上传头像.文件上传主要是将文件通过IO流传输到服务器的某一个特定的文件夹下. Why->MultipartFile? ...

最新文章

  1. Django 项目开发(三)
  2. php高效下载文件,LinkCache
  3. YBTOJ:斐波拉契(矩阵快速幂)
  4. 程序员面试金典 - 面试题 05.01. 插入(位运算)
  5. java读取文件封装的一个类(有部分代码借鉴别人的)
  6. python shell 运行时不打印日志_shell编程
  7. 复旦大学《高等代数学习指导书(第三版)》前言
  8. matlab电子类元件库仿真元件,matlab电力系统仿真元件.doc
  9. 12306 抢票助手 Java
  10. 现代化SharePoint经典网站
  11. c语言中八进制输出的格式说明符,C 的输入输出格式说明符讲解
  12. 塞尔之光的树心旋转机关_塞尔之光攻略心得_塞尔之光怎么创建人物 塞尔之光角色创建方法详解-公共游戏资源网...
  13. NetSuite 合并报表之外币折算差异(CTA)
  14. 【算法打卡(二分查找)---7.12】
  15. 南京车贴制作,海报车贴写真喷绘制作
  16. JavaScript刮奖效果(jquery图片刮奖插件)
  17. ARM 之 STM32F407zgt6 外设篇 ----------- FLASH 存储部分数据
  18. 抖音3D旋转相册 (源码下载)
  19. 一个资深程序员看12306 (三)
  20. springboot基于JAVA的电影推荐系统的开发与实现 附源码-毕业设计112306

热门文章

  1. Android ANR 分析
  2. 【JavaWeb】Access restriction The type is not accessible due to restriction on required library
  3. json最大长度限制_GET请求中URL的最大长度限制总结,读完之后,大部分程序员收藏了...
  4. sql datetime 加一天_PowerQuery数据库Sql.Database条件查询
  5. 过滤输入内容中是否含有特殊字符与表情
  6. Vue Router路由及路由重定向
  7. vue结合Promise及async实现高效开发。
  8. 本土化App名稱和icon
  9. LINUX 系统 安装Jexus 5.6和mono3.4 部署.net 环境
  10. 字符串操作与正则表达式