Skip to content

Instantly share code, notes, and snippets.

@malloc47
Created February 5, 2012 02:40
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 malloc47/1742150 to your computer and use it in GitHub Desktop.
Save malloc47/1742150 to your computer and use it in GitHub Desktop.
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