Skip to content

Instantly share code, notes, and snippets.

@EpocSquadron
Created August 3, 2012 16:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EpocSquadron/3248986 to your computer and use it in GitHub Desktop.
Save EpocSquadron/3248986 to your computer and use it in GitHub Desktop.
Remove files from a repo that should be ignored but you dont neccesarily want to delete from filesystem.
#!/bin/bash
# Regexes matching files and folders in the gitignore that should never be in a repo.
GITIGNORE_REGEXES=( ".+\.(diff|err|orig|log|rej|swo|swp|vi|sass-cache|sublime-project|sublime-workspace|komodoproject|esproj|espressostorage|rbc)" ".+\~" "\.\/\.(DS_Store|_.+|cache|project|settings|tmproj|komodotools|hg|svn|CVS|idea)" "\.\/(nbproject|Thumbs\.db|_notes|dwsync\.xml)" )
# Get rid of them in git, leave them in filesystem.
for REGEX in "${GITIGNORE_REGEXES[@]}"; do
FILES=`find -E . -iregex "$REGEX" | sed 's/^..//;' | tr '\n' ' '`
echo "## Regex: $REGEX"
if [ ! "$FILES" = "" ]; then
echo "## Files: $FILES"
git rm -rf --cached --ignore-unmatch $FILES
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment