当我尝试提交更改时,我得到这个错误:

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

如何解决这个错误?


当前回答

移动你的应用文件夹做一个备份,即mv app_folder app_folder_bk(它就像一个git stash) Git克隆your_repository 最后,打开一个合并工具(我在Linux上使用Meld diff查看器,在Windows上使用WinMerge),从右边(app_folder_bk)复制更改到左边(new app_folder)(这就像一个git stash应用)。

这是所有。也许这不是最好的方法,但我认为它很实用。

其他回答

我也遇到过类似的问题。我的笔记本电脑在Git操作期间没电了。嘘。

我没有备份。(注意:Ubuntu One不是Git的备份解决方案;它将有助于覆盖你的健全的存储库与你的损坏。)

对于Git向导,如果这是一种糟糕的修复方法,请留下评论。然而,它确实对我有用……至少暂时是这样。

第一步:备份。git文件夹(事实上我在每一步之间都会做一些改变,但是会有一个新的copy-to名称,例如。git-old-1, .git-old-2,等等):

cd ~/workspace/mcmc-chapter
cp -a .git .git-old

步骤2:执行git fsck——full命令

git fsck --full

error: object file .git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e is empty
fatal: loose object 8b61d0135d3195966b443f6c73fb68466264c68e (stored in .git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e) is corrupt

步骤3:删除空文件。我想管他呢;反正是空白的。

rm .git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e

rm: remove write-protected regular empty file `.git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e'? y

步骤3:重新执行git fsck命令。继续删除空文件。您也可以cd到.git目录并运行find。-type f -empty -delete -print删除所有空文件。最终Git开始告诉我它实际上在对对象目录做一些事情:

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

步骤4:在删除所有空文件后,我最终得到了git fsck实际运行:

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

步骤5:尝试git reflog。失败是因为我的头坏了。

git reflog

fatal: bad object HEAD

步骤6:谷歌。发现这些。手动获取reflog的最后两行:

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

步骤7:注意,从步骤6中我们了解到HEAD当前指向最后一次提交。让我们看一下父commit

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

它工作!

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

git update-ref HEAD 9f0abf890b113a287e10d56b66dbab66adc1662d

它没有抱怨。

步骤9:看看fsck说了什么:

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

第10步:缓存树中无效的sha1指针看起来像是来自一个(现在过时了)索引文件(源文件)。所以我杀了它,重置了存储库。

rm .git/index
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

步骤11:再次查看fsck…

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

悬垂的斑点不是错误。我不关心主人。u1conflict,现在它工作了,我不想再碰它了!

第12步:跟进我的本地编辑:

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")


git commit -a -m "recovering from the git fiasco"

[master 7922876] recovering from the git fiasco
 3 files changed, 12 insertions(+), 94 deletions(-)

git add tex/sept2012_code/example-code-testing.R
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

我假设你有一个遥控器,所有相关的变化已经推送到它。我不关心本地更改,只是希望避免删除和重新克隆大型存储库。如果您确实有重要的局部更改,您可能需要更加小心。

我的笔记本电脑死机后也遇到了同样的问题。 可能是因为它是一个很大的存储库,我有相当多的损坏的对象文件,当调用git fsck—full时,每次只出现一个,所以我写了一个小的shell一行程序来自动删除其中一个:

$ sudo rm ' git fsck,满2 > & 1 | grep oe - m 1 " . /对象/ [0-9a-f] {2} [0-9a-f] *”的

2>&1将错误消息重定向到标准输出,以便能够对其进行grep 使用的Grep选项: -o只返回行中实际匹配的部分 -E启用高级正则表达式 -m 1确保只返回第一个匹配项 [0-9a-f]{2}匹配0到9之间的任意字符,如果a和f同时出现,则匹配a和f [0-9a-f]*匹配0到9之间且a和f同时出现的任意数量的字符

它一次仍然只删除一个文件,所以你可能想在循环中调用它,就像:

$ while为true;做sudo rm的git fsck,满2 > & 1 | grep oe - m 1 " . /对象/ [0-9a-f] {2} [0-9a-f] *”的;完成

这样做的问题是,它不再输出任何有用的东西,所以您不知道它什么时候完成(一段时间后它应该不会做任何有用的事情)。

为了“修复”这个问题,我只需要在每一轮之后调用git fsck—full,如下所示: $ while为true;做sudo rm的git fsck,满2 > & 1 | grep oe - m 1 " . /对象/ [0-9a-f] {2} [0-9a-f] *”的;Git FSCK—满;完成

它现在的速度大约是原来的一半,但它确实输出了它的“状态”。

在这之后,我玩了一些建议在这里的答案,最后得到了一个点,我可以得到藏匿和藏匿掉很多破碎的东西。

第一个问题解决了

后来我还是有这样一个问题: 无法解析引用'refs/remotes/origin/$branch':引用破裂,可以通过 $ rm \repo.git\refs\remotes\origin$branch

$ git fetch

然后我做了一个 $ git gc -prune=现在

$ git远程修剪来源

为了更好地衡量

Git reflog expire -stale-fix -all

当运行git fsck——full时,清除错误:HEAD: invalid reflog entry $blubb。

这种情况也经常发生在我身上。我没有制定具体何时发生这种情况的协议,但我怀疑每当我的虚拟机(VM)“意外”存在时就会发生这种情况。如果我关闭虚拟机窗口(我使用的是Ubuntu 18.04 (Bionic Beaver))并重新开始,事情总是(?)工作。但是如果当我的笔记本电脑关闭(Windows主机系统)时,虚拟机窗口仍然打开,那么我经常遇到这个问题。

对于这里给出的所有答案:

thank you - they are very useful; I usually save a local copy of my code, restore the repository from remote, and move the backup copy back into the local folder. as the underlying problem is not really a Git issue, but rather a VM and/or Linux issue, I wonder if there shouldn't be a way to cure the reason rather the symptoms? Doesn't this kind of error indicate that some file system changes are not "applied" in any reasonable time, but only cached? (see for example Are file edits in Linux directly saved into disk?) -- to me it appears as if virtual Linux machines don't fsynch their stuff frequently enough. Whether this is an issue of Oracle's VirtualBox (which otherwise works very nicely) or of the guest file system, or of some settings, which we all overlook, is beyond my expertise. But I would be happy if someone could shed light on this.

我只是有同样的问题:在拉远存储库后,当我做了一个git状态,我得到:

"错误:目标文件(…)为空" “致命的:松动的物体(…)已损坏”

我解决这个问题的方法是:

git藏 错误地删除Git文件(我不确定这是必要的) Git仓库清空

我不知道到底发生了什么,但这些指示似乎让一切都变得干净了。

我遇到了同样的问题,我用了一个非常简单的方法来解决它。我发现那些丢失的文件存在于我队友的电脑上。

我将这些文件一个一个地复制到Git服务器(总共9个文件),这样就解决了这个问题。