Git - 如何从丢失的 blob 中恢复

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7347295/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:58:20  来源:igfitidea点击:

Git - how to recover from a missing blob

databasegit

提问by kbro

I'm running git 1.6.4.2. Garbage collection is failing saying "error: unable to find <SHA1>".

我正在运行 git 1.6.4.2。垃圾收集失败说“错误:无法找到<SHA1>”。

I've managed to determine that the missing object is a blob, and there is no way that I can get the blob file back. It seems that 2 scripts that run "git add" and "git commit" were running at the same time and managed to interfere with each other so that one committed a newer version of a file than the other, and the older version's blob vanished.

我已经设法确定丢失的对象是一个 blob,而且我无法取回 blob 文件。似乎运行“git add”和“git commit”的 2 个脚本同时运行并设法相互干扰,因此一个提交的文件版本比另一个新版本,而旧版本的 blob 消失了。

So what I'm trying to do now is roll back my repository to take out the commit that refers to the tree that refers to the missing blob.

所以我现在要做的是回滚我的存储库以取出引用树的提交,该树引用了丢失的 blob。

I know which branch the commit was on, so I ran "git reset" on it to rewind to the parent of the duff commit. And I know that the branch was merged somewhere else, so I rewound that branch too. So as far as I know, the duff commit/tree/blob are not referenced by anything. But if I run git prune --expire=now followed by git gc then I still get an error about the missing object.

我知道提交在哪个分支上,所以我在它上面运行了“git reset”以倒回到 duff 提交的父级。而且我知道该分支已合并到其他地方,因此我也重新绕回了该分支。所以据我所知,duff commit/tree/blob 没有被任何东西引用。但是如果我运行 git prune --expire=now 后跟 git gc 那么我仍然会收到关于丢失对象的错误。

So my question is this: how can I query the git database to find every tree object that contains the duff blob id? And how do I then find out what is causing git prune to retain it?

所以我的问题是:如何查询 git 数据库以查找包含 duff blob id 的每个树对象?然后我如何找出导致 git prune 保留它的原因?

Tricky!!

棘手!!

Thanks Kevin

谢谢凯文

采纳答案by kbro

After a bit more digging it turns out that my question is answered here: How to delete a blob from git repo- git prunewasn't pruning the stuff I'd wound back because the reflog was still referring to it. Running

经过更多的挖掘,我发现我的问题在这里得到了回答:How to delete a blob from git repo-git prune没有修剪我退回的东西,因为 reflog 仍然指的是它。跑步

git reflog expire --expire=now --all

fixed that. Also, the referenced post gives a mechanism for running git lstreeon every commit to find the referenced blob.

修好了。此外,引用的帖子提供了一种git lstree在每次提交时运行以查找引用的 blob 的机制。

回答by lolo101

I had the same problem (missing blob) and the solution with

我有同样的问题(缺少 blob)和解决方案

git reflog expire --expire=now --all

didn't do the trick. I found my solution here : https://git.wiki.kernel.org/index.php/GitFaq#How_to_fix_a_broken_repository.3F

没有做的伎俩。我在这里找到了我的解决方案:https: //git.wiki.kernel.org/index.php/GitFaq#How_to_fix_a_broken_repository.3F

This simple line

这条简单的线

git hash-object -w <file>

Fixed the missing blob.

修复了丢失的 blob。

Hope this helps.

希望这可以帮助。