Created
August 28, 2014 15:42
-
-
Save infertux/2a1e4874848ec7eb5765 to your computer and use it in GitHub Desktop.
Extract part of a Git repository while keeping 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
# create a list of files to NOT keep | |
create_black_list > blacklist | |
# add old files which have been renamed | |
for f in $(cat blacklist); do | |
git log --pretty=oneline --follow --name-only $f | grep -v ' ' | sort -u >> blacklist | |
done | |
# remove files and commits from the Git history (may take a while...) | |
for f in $(cat blacklist); do | |
echo $f | |
git filter-branch --index-filter "git rm -f --cached --ignore-unmatch $f" -f --prune-empty | |
done | |
# clone the repo to remove old git references and shrink it considerably | |
git clone file:///path/to/repo new_repo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment