Last active
August 29, 2015 13:56
-
-
Save danielpcox/8790755 to your computer and use it in GitHub Desktop.
Extract subdirectory in git, then slim down the history
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
$ git clone blahblahblah # <-- fresh clone of the repo | |
$ du -sh . | |
768M # <-- holy macaroni, that's huge | |
$ git filter-branch --subdirectory-filter path/to/subdir --prune-empty --tag-name-filter cat -- --all # <-- Actual filter | |
... | |
### Now we'll delete all references to those unchanged refs | |
$ git reflog expire --expire=now --all # <-- expire the reflog refs | |
$ rm -rf .git/refs/original | |
$ vim .git/packed-refs # <-- open this file and delete anything you were warned about as unchanged above. | |
# notice that tag refs span two lines: delete them both. | |
$ git gc --aggressive --prune=now # <-- delete all irrelevant stuff | |
$ du -sh . | |
5.4M # <-- that's a lot smaller |
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
# use git >= 1.8.5.3 ! | |
# extract subdirectory and remove references to irrelevant history | |
git clone --mirror REPO | |
cd REPO.git | |
git filter-branch --subdirectory-filter PATH/TO/SUBDIR --prune-empty --tag-name-filter cat -- --all | |
rm -rf refs/original | |
rm -f packed-refs | |
# clean up | |
git reflog expire --expire=now --all | |
git gc --aggressive --prune=now | |
git reflog expire --all --expire-unreachable=0 | |
git repack -A -d | |
git prune |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment