git:找不到 blob - 想从包中删除它

发布于 2024-12-04 12:29:18 字数 1286 浏览 4 评论 0 原文

我有一个大斑点,我想摆脱它! 我以为我使用此解决方案删除了​​该文件: http://dound.com/2009 /04/git-forever-remove-files-or-folders-from-history/ (我使用 -- --all 而不是 HEAD 以便从所有分支中删除文件)

rm -rf .git/refs/original/ && git reflog expire --all &&  
    git gc --aggressive --prune

我通过此 为什么我的 git 存储库这么大?

$ git verify-pack -v .git/objects/pack/pack-*.idx | sort -k3n
... last 4 lines:
bc7ae9801052180b283cd81880753549f0f92587 blob   19464809 749446 305054873
acd5f09a35846bec25ebc324738139e5caabc50f blob   294278199 71381636 39607483
986d152935434b56cf182d8a32e24cb57af75ac3 blob   480385718 108184804 110989119
ba9d1d27ee64154146b37dfaf42ededecea847e1 blob   761172819 27430741 277589990

脚本git-find-blob 取自 哪个提交有此 blob ?

$ ./git-find-blob ba9d1d27ee64154146b37dfaf42ededecea847e1

但它没有找到任何东西。

有什么想法如何从我的存储库中删除它吗?

I've a large blob that I want to get rid of!
I thought I removed the file using this solution:
http://dound.com/2009/04/git-forever-remove-files-or-folders-from-history/
(I've used -- --all instead of HEAD so that files are removed from all branches)

rm -rf .git/refs/original/ && git reflog expire --all &&  
    git gc --aggressive --prune

I've looked in the pack folder via this Why is my git repository so big?

$ git verify-pack -v .git/objects/pack/pack-*.idx | sort -k3n
... last 4 lines:
bc7ae9801052180b283cd81880753549f0f92587 blob   19464809 749446 305054873
acd5f09a35846bec25ebc324738139e5caabc50f blob   294278199 71381636 39607483
986d152935434b56cf182d8a32e24cb57af75ac3 blob   480385718 108184804 110989119
ba9d1d27ee64154146b37dfaf42ededecea847e1 blob   761172819 27430741 277589990

The script git-find-blob is taken from Which commit has this blob?

$ ./git-find-blob ba9d1d27ee64154146b37dfaf42ededecea847e1

But it doesn't find anything.

Any ideas how to get rid of it from my repository?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

中性美 2024-12-11 12:29:18

您可以使用 git repack -Ad 强制 git 重建您的包,并将任何无法访问的对象解包为松散对象。此时您可以使用 git gc --prune=now 丢弃无法访问的对象。

您还应该仔细检查您的转发日志是否确实已过期。我相信 git reflog expire --all 将默认为 90 天(对于无法访问的对象为 30 天),因此您可能需要使用 git reflog expire --expire-unreachable=now --all 相反(这需要在 repack+gc 之前完成)。

You can use git repack -Ad to force git to reconstruct your packs, and to unpack any unreachable objects into loose objects. At this point you can use git gc --prune=now to discard the unreachable objects.

You should also double-check that you actually expired your reflogs. I believe git reflog expire --all will default to 90 days (or 30 for unreachable objects), so you may want to use git reflog expire --expire-unreachable=now --all instead (this needs to be done before the repack+gc).

橘亓 2024-12-11 12:29:18

首先,在 git gc 调用中,您应该使用 --prune=now,因为默认情况下是保留不到 2 周的对象。

其次,默认情况下使用的 git-find-blob 命令仅在 HEAD 的历史记录中查找提交,因此如果 blob 位于另一个分支上,则该脚本会想念它的。尝试将其调用为:

./git-find-blob ba9d1d27ee64154146b37dfaf42ededecea847e1 --all

Firstly, in your git gc invocation, you should use --prune=now, since the default is to keep objects which are less than 2 weeks old.

Secondly, the git-find-blob command you've used by default only looks in the history of HEAD for commits, so if the blob is on another branch then that script will miss it. Try invoking it as:

./git-find-blob ba9d1d27ee64154146b37dfaf42ededecea847e1 --all
征﹌骨岁月お 2024-12-11 12:29:18

您想要使用 BFG Repo-Cleaner,它是 git-filter-branch 设计用于从 Git 存储库中删除大文件

下载 Java jar(需要 Java 6 或更高版本)并运行以下命令:

$ java -jar bfg.jar  --strip-blobs-bigger-than 20M  my-repo.git

任何大小超过 20M 的 blob(不在您的最新提交中)都将从您的存储库历史记录中完全删除。然后,您可以使用 git gc 清理无效数据:

$ git gc --prune=now --aggressive

BFG 通常比运行 git-filter-branch 快 10-50 倍,并且选项是围绕这两个选项定制的常见用例:

  • 删除疯狂的大文件
  • 删除密码、凭据和其他私人数据

完全披露:我是 BFG Repo-Cleaner 的作者。

You want to use the BFG Repo-Cleaner, a faster, simpler alternative to git-filter-branch designed for removing large files from Git repos.

Download the Java jar (requires Java 6 or above) and run this command:

$ java -jar bfg.jar  --strip-blobs-bigger-than 20M  my-repo.git

Any blob over 20M in size (that isn't in your latest commit) will be totally removed from your repository's history. You can then use git gc to clean away the dead data:

$ git gc --prune=now --aggressive

The BFG is typically 10-50x faster than running git-filter-branch and the options are tailored around these two common use-cases:

  • Removing Crazy Big Files
  • Removing Passwords, Credentials & other Private data

Full disclosure: I'm the author of the BFG Repo-Cleaner.

病女 2024-12-11 12:29:18

该斑点不会出现在干净推送的另一侧,因此这将是我的解决方案(推送到新位置,然后从该位置克隆)。有更简单的方法吗?

The blob doesn't appear on the other side of a clean push, so this will be my solution (push to a new location, then clone from that location). Any easier way of doing it?

等风来 2024-12-11 12:29:18

有同样的问题。发现我的麻烦 blob 被一棵无法访问的树引用了。添加到 git-find-blob 脚本:

git fsck --full --unreachable | \
while read unreachable obj tree
do
    if [[ ! $obj == "tree" ]]; then
        continue
    fi
    if git ls-tree -r $tree | grep -q "$obj_name" ; then
        echo "$unreachable $obj $tree"
    fi
done

我能够使用 BFG Repo-Cleaner 删除 blob,但我更乐意使用本机 git 命令解决问题。

Having the same issue. Discovered my troublesome blob is referenced by an unreachable tree. Adding to the git-find-blob script:

git fsck --full --unreachable | \
while read unreachable obj tree
do
    if [[ ! $obj == "tree" ]]; then
        continue
    fi
    if git ls-tree -r $tree | grep -q "$obj_name" ; then
        echo "$unreachable $obj $tree"
    fi
done

I was able to remove the blob using BFG Repo-Cleaner but I'd be much happier solving the problem using native git commands.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文