git - 为什么用BFG删除后还能看到文件

标签 git git-rewrite-history bfg-repo-cleaner

这是我所做的步骤:

  1. 创建了一个空文件夹。

  2. 使用以下方式镜像我的存储库:

    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
    
  3. 使用以下命令获取 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
    
  4. 假设最大文件的名称为 largestFile.log

  5. 然后我运行 bfg 如下:

     java -jar bfg-1.14.0.jar --delete-files 'largestFile.log'
    
  6. 上述命令的输出显示文件已成功删除:

    Deleted files
    -------------
    
     Filename                       Git id
     ------------------------------------------------
     largestFile 2015-05-18.log | bbaaa106 (1.3 GB)
    
  7. 最后,根据上面第 6 步的输出的建议,我接下来运行了以下命令:

    git reflog expire --expire=now --all && git gc --prune=now --aggressive
    
  8. 这也成功完成。

现在,在推送之前,我想确保该文件确实已被删除。所以我重新运行上面步骤 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:

https://rtyley.github.io/bfg-repo-cleaner/

关于git - 为什么用BFG删除后还能看到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67892298/

相关文章:

git - 找出 Git 分支创建者

git - 如何在所有 git 消息提交中更改特定字符串?

git - 我如何将所有提交移动到另一个分支?

git - BFG Repo Cleaner 的正确使用方法

使用 BFG 后,Git 存储库只会变得更大

git - 为什么 Drone 无法读取我的用户名?

Git:意外地将冲突注释 merge 到分支中。我该如何删除它们?

git --version 命令返回与实际安装的不同的结果

git - 从 git repo 和提交历史中递归删除所有二进制文件

bitbucket - 如何将现有的 Git-p4 存储库迁移到 LFS