Skip to content

Instantly share code, notes, and snippets.

@infertux
Created August 28, 2014 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infertux/2a1e4874848ec7eb5765 to your computer and use it in GitHub Desktop.
Save infertux/2a1e4874848ec7eb5765 to your computer and use it in GitHub Desktop.
Extract part of a Git repository while keeping the history
# 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