Skip to content

Instantly share code, notes, and snippets.

@malloc47

malloc47/git-chop

Created Feb 5, 2012
Embed
What would you like to do?
Git Chopping and Cropping
#!/bin/bash
# remove a file or directory
set -e
EXPECTED_ARGS=1
E_BADARGS=65
if [ $# -lt $EXPECTED_ARGS ]
then
echo "Usage: `basename $0` [directory]"
exit $E_BADARGS
fi
git filter-branch -f --prune-empty --index-filter "git rm -rf --cached --ignore-unmatch $1"
git reflog expire --expire=now --all
git gc --aggressive --prune=now
git prune
git gc --aggressive
git repack
git repack -ad
git prune-packed
#!/bin/bash
# remove all other directories
set -e
# do this first
# git clone --no-hardlinks /XYZ /ABC
EXPECTED_ARGS=1
E_BADARGS=65
if [ $# -lt $EXPECTED_ARGS ]
then
echo "Usage: `basename $0` [directory]"
exit $E_BADARGS
fi
git filter-branch --prune-empty --subdirectory-filter $1 HEAD -- --all
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --aggressive --prune=now
git prune
git gc --aggressive
git repack
git repack -ad
git prune-packed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.