Created
February 23, 2017 02:33
-
-
Save jdowning/01dfa4ab24138d1868acc4f393c195d7 to your computer and use it in GitHub Desktop.
git-cleanup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# BEFORE | |
/tmp/git-cleanup/repo.git $ git count-objects -v | |
count: 0 | |
size: 0 | |
in-pack: 204529 | |
packs: 1 | |
size-pack: 574968 | |
prune-packable: 0 | |
garbage: 0 | |
size-garbage: 0 | |
# AFTER | |
/tmp/git-cleanup/repo.git $ git count-objects -v | |
count: 0 | |
size: 0 | |
in-pack: 201772 | |
packs: 1 | |
size-pack: 103437 | |
prune-packable: 0 | |
garbage: 0 | |
size-garbage: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# make sure you have java installed | |
mkdir /tmp/git-cleanup | |
cd /tmp/git-cleanup | |
wget http://repo1.maven.org/maven2/com/madgag/bfg/1.12.15/bfg-1.12.15.jar | |
alias bfg="java -jar bfg-1.12.15.jar " | |
git clone --mirror https://github.com/path_to/repo | |
cp -r repo.git repo.git.backup | |
cd repo.git | |
# create a list of objects you want to remove | |
git rev-list --objects --all | awk '/images_that_should_not_be.*(jpg|JPG)/ {print $1}' > ../images.txt | |
git count-objects -v | |
cd .. | |
# this does the removal. more details: https://rtyley.github.io/bfg-repo-cleaner/#usage | |
bfg --delete-files '{comma_separated,globs*.bin}' --strip-blobs-with-ids images.txt repo.git | |
cd repo.git | |
git reflog expire --expire=now --all | |
git gc --prune=now --aggressive | |
# see git-pack-size.sh for example of before/after | |
git count-objects -v | |
# WARNING: once you push, you are rewriting the history | |
# you willl want to coordinate this with teammates and | |
# have them delete their local repo and clone again once | |
# you push the 'lighter' repo | |
git push origin master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment