simra-project / simra-android

Apache License 2.0
19 stars 13 forks source link

[CHORE] Remove APK's from history #9

Closed DanielHabenicht closed 4 years ago

DanielHabenicht commented 4 years ago

Cloning the repo takes more than 10s depending on the internet connection because this repo is nearly 100MB in size:

git clone ...
Cloning into 'simra-android'...
remote: Azure Repos
remote: Found 6808 objects to send. (192 ms)
Receiving objects: 100% (6808/6808), 94.34 MiB | 6.75 MiB/s, done.
Resolving deltas: 100% (3560/3560), done.

That's because there are APKs checked into the history:

git rev-list --objects --all \
 | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \
 | sed -n 's/^blob //p' \
 | sort --numeric-sort --key=2 \
 | cut -c 1-12,41- \
 | $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
7a3265ee94c0   53KiB gradle/wrapper/gradle-wrapper.jar
5cdcc6a9134b   73KiB app/src/main/res/font/assistant_extralight.ttf
a957b8d79c39  2.9MiB app/release/app-release.apk
f4205545829a  3.3MiB app/release/SimRa.apk
8a1145c3200a  3.3MiB app/release/simra-release-beta-v7.apk
adc5bf2b254a  3.4MiB app/release/simra-release-v8.apk
f6efae8f19ae  3.4MiB app/release/simra-release-v10.apk
864236f916dc  3.4MiB app/release/simra-release-v9.apk
b18d539c8fc1  3.4MiB app/release/simra-release-v17.apk
916333cb6aa9  3.4MiB app/release/app-release.apk
f66982e96d96  3.4MiB app/release/simra-release-v14.apk
0012b3cdb19a  3.4MiB app/release/simra-release-v13.apk
e0d750ea60b2  3.4MiB app/release/simra-release-v18.apk
3f24794d5f95  3.4MiB app/release/app-release.apk
625ba75aa844  3.4MiB app/release/simra-release-v15.apk
d03c7767b033  3.4MiB app/release/simra-release-v16.apk
79258f0ab4d3  3.4MiB app/release/simra-release-v12.apk
6020d636305c  3.4MiB app/release/simra-release-v11.apk
5dc63f97578f  3.4MiB app/release/app-release.apk
4d363cfb30e3  3.4MiB app/release/app-release.apk
d4efc59f4f69  3.4MiB app/release/SimRa.apk
96f33b9570c9  3.4MiB app/release/SimRa.apk
1846db79301b  3.6MiB app/release/SimRa.apk
5d4e966b4b96  3.6MiB app/release/SimRa.apk
c9ed1ab9ae50  4.2MiB app/release/app-release.apk
9b9a5779a568  4.2MiB app/release/app-release.apk
25876d62d159  4.2MiB app/release/simra-release-beta.apk
3ded56f5b719  4.2MiB app/release/app-release.apk
5cd1a1623602  4.2MiB app/release/simra-beta.apk
bc792372dccd  4.2MiB app/release/simra-release-beta-v5.apk
aaa46221da6c  4.2MiB app/release/simra-release-beta-v3.apk
c174aa70a535  4.3MiB app/release/simra-release-beta-v4.apk
fbee0efe8bf8  4.3MiB app/release/app-release.apk
1416c1766e2a  4.3MiB app/release/simra-release-beta-v6.apk

I've made the same changes to in our repo to remove them, by running the following commands this could also be done in this repo.

git clone ...
cd ./this_repo
git checkout master
# This can take a while (10 minutes):
git filter-branch --index-filter 'git rm -rf --cached --ignore-unmatch app/release/' --prune-empty --tag-name-filter cat -- --all
# Remove Old refs
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
# Ensure Removal
rm -Rf .git/logs .git/refs/original
# Perform a garbage collection to remove commits with no refs
git gc --prune=all --aggressive

# Repo is only 2 MB after this 
git count-objects -vH
count: 0
size: 0 bytes
in-pack: 6647
packs: 1
size-pack: 2.19 MiB
prune-packable: 0
garbage: 0
size-garbage: 0 bytes

# Push to this repo
git push origin --all --force

From: https://stackoverflow.com/a/32886427/9277073

selphiron commented 4 years ago

fixed in #14