Created
May 13, 2013 00:18
-
-
Save jacklund/5565462 to your computer and use it in GitHub Desktop.
Prune out subdirectories from a repository using Git
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
# Get a list of the directories I'm not interested in | |
$ excludes=`echo $* | tr " " "|"` | |
$ files=`ls | egrep -v $excludes | tr "\\n" " "` | |
# Disconnect from remote for safety | |
$ git remote rm origin | |
# Get rid of all tags that don't fit my pattern | |
$ git tag -l | grep -v $pattern | xargs git tag -d | |
# Prune the directories I'm not interested in | |
$ git filter-branch --tag-name-filter cat --prune-empty \ | |
--tree-filter "rm -rf ${files}" -- --all | |
# Reset the indexes | |
$ git reset --hard | |
# Get rid of obsolete references in the logs | |
$ git for-each-ref --format="%(refname)" refs/original/ | \ | |
xargs -n 1 git update-ref -d | |
$ git reflog expire --expire=now --all | |
$ git gc --aggressive --prune=now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment