Last active
October 29, 2018 20:51
-
-
Save vrillusions/5622099 to your computer and use it in GitHub Desktop.
workflow to filter out several folders from a git repo.
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 example.com:/url/to/project.git | |
cd project | |
# these next few commands show how to rename branch "mybranch" to master | |
git checkout mybranch | |
git branch -d master | |
git checkout -b master | |
git branch -d mybranch | |
# remove orgin to make sure we don't accidentally do anything there | |
git remote rm origin | |
# none of the tags apply to mybranch | |
git tag -l | xargs git tag -d | |
# this version didn't work | |
#git filter-branch --index-filter "git rm -r -f --cached --ignore-unmatch $(ls -xd common/!(classes) common/!(includes) html/!(webtools) includes/!(webtools))" --prune-empty -- --all | |
# use the greps to exclude what you want to keep | |
# BUG: this doesn't filer out files with spaces in them | |
git filter-branch --prune-empty \ | |
--index-filter 'git ls-tree -r --name-only --full-tree $GIT_COMMIT | \ | |
egrep -v "^lib/(library1|library2)" | \ | |
grep -v "^app/includes" | \ | |
grep -v "^data/myapp" | \ | |
xargs git rm --cached --ignore-unmatch -r -f' -- --all | |
# BUG: If it doesn't filter out files with spaces you can use something like | |
# the following. Note here you are specifying the files you want to delete | |
# instead of excluding what you don't want. | |
git filter-branch --force --index-filter 'git rm -r -f --cached --ignore-unmatch "data/content with spaces.txt' --prune-empty -- --all | |
# Next 4 commands remove all the old history for good from local repo | |
git reset --hard | |
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d | |
git reflog expire --expire=now --all | |
git gc --prune=now | |
# Now add the origin to new project name and push it | |
git remote add origin example.com:/url/to/project2.git | |
git push -u origin master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment