Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Aug 25, 2014

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
You can’t perform that action at this time.