Reduce Git repository size
Created by: rtyley
I'm the author of the BFG Repo-Cleaner, a faster, simpler alternative to git filter-branch
, and @SecUpwN asked me how I would go about reducing the size of Android-IMSI-Catcher-Detector's Git repo, working on the assumption that the large size of the repo is off-putting for potential new contributors (see also #362 (closed)).
The repository currently has a packfile of 34M, which can't be considered huge, but there's potential for reducing it down to around half of it's current size. It's up to you to decide if that's a benefit worth pursing - remember that commit ids change will change!
Before rewriting history, I'd recommend removing all the unwanted cruft from the current filetree, eg screenshots and jars under https://github.com/SecUpwN/Android-IMSI-Catcher-Detector/tree/development/app/libs - unless there is some reason why these jars can't become gradle dependencies?
Run the BFG over a mirror clone of your repository - a fresh copy of the clone each time is best. The BFG is extremely fast to run, so you can experiment with a few different thresholds for removal, and see what gets deleted (the BFG produces a deleted.txt
report for every run, listing every removed file).
Prepare your contributors for history to be rewritten. Any outstanding pull requests will need to be rebased against the new history, and in general, your contributors will be best off just deleting their current working copy, and cloning a new one, to ensure they don't push dirty history back to your new repo.
After a few tests, I ran the BFG against your repo with --strip-blobs-bigger-than 128K
, which was about as aggressive as I could get without removing the history of AimsicdService.java
, which has been very big in the past. Almost all the removed files were pngs & svgs. This yielded a new pack-size of 21M:
$ git clone --mirror git@github.com:bfg-repo-cleaner-demos/Android-IMSI-Catcher-Detector.git
$ cd Android-IMSI-Catcher-Detector.git/
$ ls -lh objects/pack/pack-*.pack
-r--r--r-- 1 roberto roberto 34M Apr 16 20:41 objects/pack/pack-c62cb2f13a93ac0d05d91a872ca4a5bd78ebec2e.pack
$ java -jar ~/bfg.jar --strip-blobs-bigger-than 128K
$ git reflog expire --expire=now --all && git gc --prune=now --aggressive
$ ls -lh objects/pack/pack-*.pack
-r--r--r-- 1 roberto roberto 21M Apr 16 20:45 objects/pack/pack-ea5c8acab0f465cf4234daf0cdb763fb85f3694c.pack
$ git push
...the BFG protects every file in your current commit, so this run was held back a bit by all the big files currently sitting in your file tree - getting down to about 16M would be possible with a bit more clear-up.
The cleaned repository is available at https://github.com/bfg-repo-cleaner-demos/Android-IMSI-Catcher-Detector if you'd like to check it out. Good luck with your project, I wish you every success!