简体   繁体   中英

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:

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:

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. 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

or

git gc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM