这是我所做的步骤:
创建了一个空文件夹。
使用以下方式镜像我的存储库:
git clone --mirror <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="95f2fce1d5f7fce1f7e0f6fef0e1bbfae7f2" rel="noreferrer noopener nofollow">[email protected]</a>:somespace/myrepo.git
使用以下命令获取 10 个最大文件的列表:
git rev-list --objects --all \ | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \ | sed -n 's/^blob //p' \ | sort --numeric-sort --key=2 \ | tail -n 10 \ | cut -c 1-12,41- \ | $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
假设最大文件的名称为
largestFile.log
然后我运行
bfg
如下:java -jar bfg-1.14.0.jar --delete-files 'largestFile.log'
上述命令的输出显示文件已成功删除:
Deleted files ------------- Filename Git id ------------------------------------------------ largestFile 2015-05-18.log | bbaaa106 (1.3 GB)
最后,根据上面第 6 步的输出的建议,我接下来运行了以下命令:
git reflog expire --expire=now --all && git gc --prune=now --aggressive
这也成功完成。
现在,在推送之前,我想确保该文件确实已被删除。所以我重新运行上面步骤 3 中的命令。但其输出仍然在列表中显示 largestFile.log
。
我做错了什么?或者我在这里缺少什么?
有人可以解释或指导我吗?
谢谢!
最佳答案
精细手册说,如果没有 --no-blob-protection
选项,HEAD 提交将保持不变。这是你的问题吗?
By default the BFG doesn't modify the contents of your latest commit on your master (or 'HEAD') branch, even though it will clean all the commits before it.
That's because your latest commit is likely to be the one that you deploy to production, and a simple deletion of a private credential or a big file is quite likely to result in broken code that no longer has the hard-coded data it expects - you need to fix that, the BFG can't do it for you. Once you've committed your changes- and your latest commit is clean with none of the undesired data in it - you can run the BFG to perform it's simple deletion operations over all your historical commits
...
If you want to turn off the protection (in general, not recommended) >you can use the --no-blob-protection flag:
关于git - 为什么用BFG删除后还能看到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67892298/