git ls-files, how to escape spaces in files paths?
The canonical way:
git ls-files -z | xargs -0 git rm
another way:
git ls-files | xargs -d '\n' git rm
Rachel Duncan's answer got me set in the right direction, and I've found a solution that works! I also borrowed tips from https://superuser.com/questions/401614/inserting-string-from-xargs-into-another-string
git ls-files -i --exclude-from=.gitignore | tr '\n' '\0' | xargs -0 -L1 -I '$' git rm --cached '$'
The above script compiles a list of all of your versioned git files that now fall within the .gitignore rules of exclusion, wraps quotes around each std line out (file path), then executes the git rm --cached
command with the modified string.
I like this way because the terminal puts out a confirmation for each of the files it's removing from source control.
Cheers!