在已经被 git -rm'ed 和 pushed 之后从 git repo 中删除提交的内容

问题描述 投票:0回答:1

所以我们有一个用户在她的工作区中添加然后删除一个大的文件目录,这是两个不同的提交。然后,她将她的更改推送到中央仓库,而对于最终用户来说,这看起来像是一个空洞。问题是我们的中央仓库因此而增加了 50 倍。我已经用过滤器分支尝试了几件事,但它只是不起作用。

所以添加的文件夹在根级别。它的名字是.core

我尝试了以下基于链接的过滤器分支:

http://www.somethingorothersoft.com/2009/09/08/the-definitive-step-by-step-guide-on-how-to-delete-a-directory-permanently-from-git-on-寡妇换笨蛋像我自己/

http://dound.com/2009/04/git-forever-remove-files-or-folders-from-history/

从 git 中永久删除目录

我尝试过的最终命令如下所示:

git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch .core" --prune-empty --tag-name-filter cat -- --all
rm -Rf .git/refs/original
rm -Rf .git/refs/logs
git reflog expire --expire=now --all && git gc --prune=now --aggressive

结果输出表明 Ref 未更改。我尝试将 .core 的引用更改为各种变体,例如 ./.core、*.core/*、..... 没有任何内容被删除。

谢谢。

git git-filter-branch
1个回答
3
投票

使用 BFG,它是

git-filter-branch
的更简单、更快速的替代方案,专门用于从 Git 历史记录中删除不需要的文件。

仔细按照BFG的使用说明 - 核心部分就是这样:

$ java -jar bfg.jar  --delete-folders .core  my-repo.git

任何名为

.core
的文件夹(不在您的 latest 提交中)将从您的 Git 存储库的历史记录中删除。然后您可以使用
git gc
清除死数据:

$ git reflog expire --expire=now --all && git gc --prune=now --aggressive

BFG 通常比运行 git-filter-branch 快至少

10-720x
,并且通常更易于使用。

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

© www.soinside.com 2019 - 2024. All rights reserved.