Git 日志:致命对象 [sha1] 已损坏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2909225/
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 log: fatal object [sha1] is corrupted
提问by Keyo
Is there any way I can repair my repository with commit history in tact.
有什么办法可以用机智的提交历史修复我的存储库。
# git log
fatal: object 01aeb2bf2e93b238f0e0422816b3e55518321ae7 is corrupted
From reading the link below it looks like I'll have zap it and start over.
从阅读下面的链接看来,我将对其进行处理并重新开始。
采纳答案by Bram Schoenmakers
回答by Jase
I wound up in the same situation, probably due to an improper shutdown of the virtual machine I was working in. There were approximately 10 objects in .git/objects that had zero length. As far as I can tell, the actual source code files were fine, just the repository was hosed.
我遇到了同样的情况,可能是由于我工作的虚拟机不正确关闭。 .git/objects 中大约有 10 个对象的长度为零。据我所知,实际的源代码文件很好,只是存储库被冲洗掉了。
$ git status
fatal: object fbcf234634ee04f8406cfd250ce5ab8012f92b08 is corrupted
Per some suggestions I saw elsewhere (including Linus's post referenced above), I tried temporarily moving the corrupted objects git was complaining about from .git/objects elsewhere. When had moved all of them, I got:
根据我在别处看到的一些建议(包括上面引用的 Linus 的帖子),我尝试暂时将 git 抱怨的损坏对象从 .git/objects 移到别处。当移动所有这些时,我得到:
$ git status
fatal: bad object HEAD
After about an hour of Googling and trying various solutions, I gave up and started a new working copy using 'git clone' to pull from the origin (which was about 2 hours behind my working copy). I then used rsync -rC
(-C excludes SCM files) to copy the changed files from the messed-up working copy to my new working copy.
经过大约一个小时的谷歌搜索并尝试了各种解决方案后,我放弃了并使用“git clone”从源中拉出一个新的工作副本(这比我的工作副本晚了大约 2 小时)。然后我使用rsync -rC
(-C 不包括 SCM 文件)将更改的文件从混乱的工作副本复制到我的新工作副本。
回答by Denis Gorbachev
You could also try to restore these objects by merely copying them from other repositories.
您也可以尝试通过仅从其他存储库复制这些对象来恢复这些对象。
My virtual machine crashed while recording a pushed commit, so the objects were safely stored on a local computer. I scp'ed them to virtual machine and voila — git fsck outputs no errors.
我的虚拟机在记录推送提交时崩溃,因此对象安全地存储在本地计算机上。我将它们 scp 到虚拟机,瞧—— git fsck 没有输出错误。
回答by Anson Kao
Simply delete the corrupt object that git is complaining about. I was able to resolve the same issue just now this way.
只需删除 git 抱怨的损坏对象。我刚刚能够通过这种方式解决同样的问题。
fatal: object 985a4870e7d890b314d2794377045a8b007c7925 is corrupted
For the above error, I was able to find corresponding object at:
对于上述错误,我能够在以下位置找到相应的对象:
project_directory/.git/objects/98/5a4870e7d890b314d2794377045a8b007c7925
Where you can see the file is 0 bytes and deleting it allowed the fetch to start working.
你可以看到文件是 0 字节,删除它允许提取开始工作。
Presumably the previous fetch was interrupted, leaving the corrupt object with size = 0 bytes.
推测之前的提取被中断,留下大小为 0 字节的损坏对象。
回答by cube45
Had the same problem, whichever git command I ran, It ended up with the message:
遇到了同样的问题,无论我运行哪个 git 命令,结果都是这样的:
fatal: object <hash> is corrupted
I didn't have a backup and didn't want to lose my commits, so I decided to try Jase's solution and removed the 0 length file I had : .git/objects/00/<hash>
Then got the same:
我没有备份并且不想丢失我的提交,所以我决定尝试 Jase 的解决方案并删除我拥有的 0 长度文件:.git/objects/00/<hash>
然后得到相同的:
$ git status
fatal: bad object HEAD
Then, I tried to know what was wrong and looked into .git/refs/heads/master
where I had the hash.
然后,我试图知道出了什么问题并查看.git/refs/heads/master
了哈希值的位置。
I looked into .git/logs/refs/head/master
and found lines like this one:
我查看.git/logs/refs/head/master
并找到了这样的行:
<old commit> <new commit> <author> <timestamp> commit: <commit message>
I removed the last line (which had =) and pasted of this line into .git/refs/heads/master
, erasing its content
我删除了最后一行(其中有 =)并将这一行粘贴到 中.git/refs/heads/master
,擦除其内容
I was then able to commit successfully.
然后我就能够成功提交。
回答by Danny Virasawmi
I had this same issue. I noticed that I wasn't logged in as root. When I logged in as root, I was able to check the log without the error sign.
我有同样的问题。我注意到我没有以 root 身份登录。当我以 root 身份登录时,我能够检查没有错误标志的日志。
To solidify this good status, I did this:
为了巩固这种良好状态,我这样做了:
git add .
git commit -a -m "stabilize git"
I exited out of root and tried pulling from a client. It worked out for me afterwards.
我退出 root 并尝试从客户端拉取。后来它对我有用。
When I did the add and commit, I knew that I was fine with what was in the directory. I had no changes visible through "git status".
当我添加和提交时,我知道我对目录中的内容没有问题。我没有通过“git status”看到任何变化。