Skip to content

Instantly share code, notes, and snippets.

@wilsonianb
Created February 15, 2017 20:57
Show Gist options
  • Save wilsonianb/67732894ddc1cf00367013b2f47db353 to your computer and use it in GitHub Desktop.
Save wilsonianb/67732894ddc1cf00367013b2f47db353 to your computer and use it in GitHub Desktop.
git-filter-branch
# Remove everything except specific files/directories
git filter-branch -f --prune-empty --index-filter \
'git rm --cached -r -q -- . ; git reset -q $GIT_COMMIT -- my-file my-dir' -- --all
# Remove specified files/directories
git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch my-file my-dir' HEAD
# Move file
git filter-branch --tree-filter '
if [ -f current-dir/my-file ]; then
mv current-dir/my-file new-dir/
fi' --force HEAD
# Reduce repo to specified directory
git filter-branch --subdirectory-filter my-fav-dir -- --all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment