Skip to content

Instantly share code, notes, and snippets.

@paulboardman
Created November 12, 2015 11:17
Show Gist options
  • Save paulboardman/34ca445b95026d3450b3 to your computer and use it in GitHub Desktop.
Save paulboardman/34ca445b95026d3450b3 to your computer and use it in GitHub Desktop.
Git: remove files from index that are listed in .gitignore
# list the files in the index that are ignored via patterns in .gitignore
git ls-files -i --exclude-from=.gitignore
# remove these files - assuming filenames with no spaces or special characters
git rm --cached $(git ls-files -i --exclude-from=.gitignore)
# remove these files - assuming filenames with spaces (urgh!)
git ls-files -i --exclude-from=.gitignore -z | xargs -0 git rm --cached
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment