Skip to content

Instantly share code, notes, and snippets.

@stepmr
Created April 10, 2013 18:00
Show Gist options
  • Save stepmr/5356934 to your computer and use it in GitHub Desktop.
Save stepmr/5356934 to your computer and use it in GitHub Desktop.
Remove previously commit files in update .gitignore - ala http://stackoverflow.com/questions/7527982/applying-gitignore-to-committed-files
After editing .gitignore to match the ignored files, you can do git ls-files -ci --exclude-standard to see the files that are included in the exclude lists; you can then do git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached to remove them from the repository (without deleting them from disk).
Edit: You can also add this as an alias in your .gitconfig file so you can run it anytime you like. Just add the following line under the [alias] section:
apply-gitignore = !git ls-files -ci --exclude-standard -z | xargs -0r git rm --cached
(The -r flag in xargs prevents git rm from running on an empty result and printing out its usage message.)
Now you can just type git apply-gitignore in your repo, and it'll do the work for you!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment