简体   繁体   English

如何使用BFG清除HEAD中当前不存在的所有git历史记录和文件斑点

[英]How do I clean all git history and blobs of files not currently present in HEAD with BFG

I want to clean all blobs and history of files that have been previously deleted (ie no longer present in HEAD), I am currently running these commands, but BFG seems deleting all blobs, including those present in HEAD: 我想清除所有Blob和以前删除过的文件的历史记录(即HEAD中不再存在),我目前正在运行以下命令,但是BFG似乎删除了所有Blob,包括HEAD中存在的那些Blob:

git log  # Returns 1050 commits
git commit -a -m "Clean the old history and blobs with BFG"
java -jar bfg.jar --delete-files '*'  # Delete all files not in HEAD
git log  # Still returns 1050 commits, all empty
git diff 5458b2^ 5458b2  # Returns 0 change, while it concerns a protected file

BFG actually took into account the protected files in HEAD, like gitignore for example: BFG实际上考虑了HEAD中受保护的文件,例如gitignore:

Protected commits
-----------------
These are your protected commits, and so their contents will NOT be altered:
 * commit 22a1ebd3 (protected by 'HEAD') - contains 1451 dirty files : 
    - .gitignore (813 B)
    - ...

But they are removed anyway, while they are supposed to be protected: 但是无论如何,它们都会被删除,而应该受到保护:

Deleted files
-------------
    Filename     Git id  
    ----------------------------------------
    .gitignore | 091217cf (672 B), 17e3d7c5 (227 B)...                          

I am finally using that script to clean up the repository from obsolete deleted files. 我最终使用该脚本从过时的已删除文件中清理存储库。 It combines several steps of branch rewritings and garbage collector call to clean the current repository. 它结合了分支重写和垃圾回收器调用的几个步骤,以清理当前存储库。

I managed to compress a 700MB heavy repo in a 4MB fresh repository. 我设法在4MB的新存储库中压缩了700MB的大型仓库。 As usual, duplicate your repository before running this kind of script, it might result in some lost of data! 与往常一样,在运行这种脚本之前,请复制存储库,这可能会导致数据丢失!

Maybe you can try the following command to delete all unreachable objects. 也许您可以尝试使用以下命令删除所有无法访问的对象。

git prune git prune

or 要么

git gc git gc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 git:如何从 git 历史记录中删除当前不存在的*所有*文件? - git: How to remove *all* files from the git history that are not currently present? 过滤出当前HEAD中不存在的所有项目的Git历史记录 - Filter out Git history for all items NOT present in current HEAD 用BFG清理git历史 - cleaning git history with BFG 在git或git-svn中,如何修改历史记录以仅包含当前HEAD上存在的文件? - In git or git-svn, how do I modify history to only contain files which exist on my current HEAD? 使用BFG重写git历史记录后是否需要垃圾回收 - Do I need Garbage Collection after using BFG to rewrite git history 如何将另一个git存储库导入为子目录,其所有历史记录分组在提交日志的HEAD中? - How do I import another git repository as a sub-directory with all of its history grouped at the HEAD of the commit log? 如何清理我的 git 分支以保持干净的历史记录? - How do I clean up my git branches to have a clean history going forward? 如何清理git历史? - How to clean git history? 如何在没有历史的情况下将最新的头/主人从GIT推入SVN? - How do you push the latest head/master into SVN from GIT without all the history? git-svn克隆所有历史记录,但仅克隆HEAD版本中的当前历史记录 - git-svn clone all history but only what's currently in HEAD revision
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM