Skip to content

Instantly share code, notes, and snippets.

@atnan
Created September 21, 2009 00:41
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save atnan/190002 to your computer and use it in GitHub Desktop.
Save atnan/190002 to your computer and use it in GitHub Desktop.
#!/bin/bash
cat .gitignore | egrep -v "^#|^$" | while read line; do
if [ -n "$line" ]; then
OLD_IFS=$IFS; IFS=""
for ignored_file in $( git ls-files "$line" ); do
git rm --cached "$ignored_file"
done
IFS=$OLD_IFS
fi
done
@Utumno
Copy link

Utumno commented Aug 6, 2014

Could you add a description of what this is doing ? Are .gitignore entries directories ? In this case would git rm -r --cached suffice instead of the for loop ?

@nathannis
Copy link

I couldn't quite get that to work in git shell (in windows), but used this one-liner instead
git ls-files --ignored --exclude-standard | sed 's/^.*$/"&"/g' | xargs git rm --cached

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment