Git 推送错误:对象文件为空/松散对象已损坏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37312928/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git push error: object file is empty/loose object is corrupt
提问by Joe Morano
I was attempting to perform a git commit using Git Gui. I staged a few files, and then my computer suddenly shut off due to low battery. I plugged it in, turned it back on, and committed the files I wanted to. Then I ran git push
, like I've done a million times before with no issues, and this time I got the following error:
我试图使用 Git Gui 执行 git commit。我暂存了几个文件,然后由于电池电量不足,我的计算机突然关闭了。我插入它,重新打开它,并提交我想要的文件。然后我跑了git push
,就像我之前做过一百万次没有问题一样,这次我得到了以下错误:
Counting objects: 8, done.
error: object file .git/objects/b5/60c934f6bad40f4f246973afc0139ed91a2d32 is empty
Compressing objects: 100% (4/4), done.
error: object file .git/objects/b5/60c934f6bad40f4f246973afc0139ed91a2d32 is empty
fatal: loose object b560c934f6bad40f4f246973afc0139ed91a2d32 (stored in .git/objects/b5/60c934f6bad40f4f246973afc0139ed91a2d32) is corrupt
error: failed to push some refs to '[email protected]:joemorano/app.git'
Could this have been caused by the computer shutting off before I could perform the first commit?
这可能是由于在我执行第一次提交之前计算机关闭造成的吗?
Right before all this happened, I apparently corrupted the production version of my app by running bundle install
as root on my server, and now everything on the server is messed up, but I don't see how that could affect the local version. I never did git pull
or anything like that.
就在这一切发生之前,我显然bundle install
以 root 身份在我的服务器上运行破坏了我的应用程序的生产版本,现在服务器上的一切都搞砸了,但我不知道这会如何影响本地版本。我从来没有做过git pull
或类似的事情。
Anyone encounter this error before?
有人遇到过这个错误吗?
采纳答案by torek
... failed to push some refs to '[email protected]:joemorano/app.git'
Could this have been caused by the computer shutting off before I could perform the first commit?
... failed to push some refs to '[email protected]:joemorano/app.git'
这可能是由于在我执行第一次提交之前计算机关闭造成的吗?
Definitely, yes.
肯定的,是的。
Anyone encounter this error before?
有人遇到过这个错误吗?
Repair corrupted git repository
See also: How to fix corrupted git repository?
另请参阅:如何修复损坏的 git 存储库?
In this case, since you (presumably) have a non-corrupt backup on bitbucket, I'd start by cloning that to a fresh (good) clone, then see if I could recover any intermediate commits and files from the existing (bad) clone and/or its work-tree, putting them into the new (good) clone. Once you have recovered whatever is recoverable from the bad clone, you can abandon or delete it. (Depending on your computer and its file system checking and repair tools, you might want to run those as well, perhaps before doing anything else at all.)
在这种情况下,由于你(大概)在 bitbucket 上有一个未损坏的备份,我首先将它克隆到一个新的(好的)克隆,然后看看我是否可以从现有的(坏的)中恢复任何中间提交和文件克隆和/或其工作树,将它们放入新的(好的)克隆中。一旦您恢复了可从坏克隆中恢复的任何内容,您就可以放弃或删除它。(根据您的计算机及其文件系统检查和修复工具,您可能还想运行它们,也许在执行任何其他操作之前。)
回答by Akshay Borade
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.):
第 1 步:备份 .git(实际上,我在每一步更改某些内容之间执行此操作,但使用新的复制对象名称,例如 .git-old-1、.git-old-2 等) :
cp -a .git .git-old
Step 2: Run
第 2 步:运行
git fsck --full
you will get this error message
你会收到这个错误信息
For example: error: object file .git/objects/0A/dsdadadadaaeer4r3434343434334f is empty
例如:错误:目标文件 .git/objects/0A/dsdadadadaaeer4r3434343434334f 为空
Step 3: Remove the above empty file this is in your .git/objects/
folder. Continue deleting the empty files.
第 3 步:删除您.git/objects/
文件夹中的上述空文件。继续删除空文件。
Step 4: After deleting all of the empty files, now run
第 4 步:删除所有空文件后,现在运行
git fsck --full
Step 5: Try git reflog. Fail because HEAD is broken.
第 5 步:尝试 git reflog。失败,因为 HEAD 坏了。
Step 6: Manually get the reflog:
第 6 步:手动获取 reflog:
git log origin/master..HEAD
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:
第 7 步:请注意,从第 6 步我们了解到 HEAD 当前指向最后一次提交。所以让我们试着只看一下父提交:
git show commit-id
Step 8: So now we need to point HEAD to commit-id
第 8 步:所以现在我们需要将 HEAD 指向 commit-id
git update-ref HEAD commit-id
Hope this will work for you.
希望这对你有用。
回答by Vimalraj
It is because of corrupted head object filesresiding in local .gitfolder.
这是因为驻留在本地.git文件夹中的头部对象文件损坏。
Following the below commands enabled to view previous refs and track back the commit.
按照以下命令启用查看以前的引用并跟踪提交。
git symbolic-ref HEAD refs/remotes/origin/master // resetting to branch refs inside .git folder manually
git status // now we can use git log to find the latest commit. which will be clean to master.
git reflog // to track back lost commit.
git reset HEAD@{5} // resetting hard to refs with the changes.
It is found that sometimes the diff changes are presentby resetting with the commit, where changes are not presentin the physicallybefore.
发现有时通过使用commit重置而存在差异更改,而之前的物理更改不存在。
So, we did a soft resetwith the commit ID and used difftool to manually set the changes that were lost.
因此,我们 对提交 ID进行了软重置,并使用 difftool 手动设置丢失的更改。
回答by user2189436
**
**
A SIMPLE SOLUTION after struggling a bit
挣扎了一下后的简单解决方案
**
**
I faced the similar issue.
我遇到了类似的问题。
> $ git push error: object file
> .git/objects/65/05c1876d9c4f89b9f65949052af3495ae039cd is empty error:
> object file .git/objects/65/05c1876d9c4f89b9f65949052af3495ae039cd is
> empty error: object file
> .git/objects/65/05c1876d9c4f89b9f65949052af3495ae039cd is empty fatal:
> loose object 6505c1876d9c4f89b9f65949052af3495ae039cd (stored in
> .git/objects/65/05c1876d9c4f89b9f65949052af3495ae039cd) is corrupt
> error: remote unpack failed: eof before pack header was fully read
Then I just removed that empty object file
然后我只是删除了那个空的目标文件
$ rm .git/objects/65/05c1876d9c4f89b9f65949052af3495ae039cd
Boom I can do git push now.
Boom 我现在可以做 git push 了。
$ git push
Enumerating objects: 41, done.
Counting objects: 100% (41/41), done.
Delta compression using up to 4 threads
Compressing objects: 100% (21/21), done.
Writing objects: 100% (22/22), 3.82 KiB | 1.91 MiB/s, done.
Total 22 (delta 15), reused 0 (delta 0)
remote:
remote: View pull request for feature/*BranchName*
> error: failed to push some refs to 'ssh://[email protected]
I tried $git gc
though which made me remove some file -- do not do this
我试过$git gc
了,这让我删除了一些文件——不要这样做