準備條件
- [下載 BFG工具] (https://rtyley.github.io/bfg-repo-cleaner/)
- 安裝 java 運行環(huán)境
使用方法
下載官網的程序包。例如我這里下載的為bfg-1.13.0.jar,之后將程序包放到一個文件夾里.注意:bfg-1.13.0.jar改名為bfg
-
克隆倉庫的 git repo,使用--mirror參數,克隆完成后,example.git 和 bfg 放到一個文件中
git clone --mirror https://github.com/example.git -
清除大文件,文件夾,隱私文件
-
這里官網給出的命令是這樣的。第一句是刪除文件,第二句是刪除文件夾,兩個語句的區(qū)別在附加參數上。這里,不指定文件/文件夾位置,只是用名稱匹配。
java -jar bfg.jar --delete-files [文件名稱] example.git java -jar bfg.jar --delete-folders [文件夾名稱] example.git -
這樣會有一個問題,這種情況bfg會保護當前版本(HEAD所指的版本),不去清理。提示如下:
Protected commits ----------------- These are your protected commits, and so their contents will NOT be altered: * commit ******* (protected by 'HEAD') -
在命令行下加入--no-blob-protection命令,可以解除保護。我使用的命令如下。
java -jar bfg.jar --delete-files libBaiduSpeechSDK.a example.git --no-blob-protection java -jar bfg.jar --delete-folders TTS example.git --no-blob-protection
-
-
清理不需要的數據
-
在完成上面的指令后,實際上這些數據/文件并沒有被直接刪除,這時候需要使用git gc指令來清除
cd example.git git reflog expire --expire=now --all && git gc --prune=now --aggressive
-
-
推送到GitHub
-
將數據推送到GitHub遠程倉庫。按照官網描述,由于之前使用了--mirror參數,推送時會推送所有內容。
git push
-