![](/img/trans.png)
[英]git: How to remove *all* files from the git history that are not currently present?
[英]How do I clean all git history and blobs of files not currently present in HEAD with BFG
我想清除所有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實際上考慮了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)
- ...
但是無論如何,它們都會被刪除,而應該受到保護:
Deleted files
-------------
Filename Git id
----------------------------------------
.gitignore | 091217cf (672 B), 17e3d7c5 (227 B)...
我最終使用該腳本從過時的已刪除文件中清理存儲庫。 它結合了分支重寫和垃圾回收器調用的幾個步驟,以清理當前存儲庫。
我設法在4MB的新存儲庫中壓縮了700MB的大型倉庫。 與往常一樣,在運行這種腳本之前,請復制存儲庫,這可能會導致數據丟失!
也許您可以嘗試使用以下命令刪除所有無法訪問的對象。
git prune
要么
git gc
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.