I have committed loads of files that I now want to ignore. How can I tell git to now ignore these files from future commits?
EDIT: I do want to remove them from the repository too. They are files created after ever build or for user-specific tooling support.
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 -0 git rm --cached
(The -r
flag in xargs
prevents git rm
from running on an empty result and printing out its usage message, but may only be supported by GNU findutils. Other versions of xargs
may or may not have a similar option.)
Now you can just type git apply-gitignore
in your repo, and it\'ll do the work for you!
to leave the file in the repo but ignore future changes to it:
git update-index --assume-unchanged <file>
and to undo this:
git update-index --no-assume-unchanged <file>
to find out which files have been set this way:
git ls-files -v|grep \'^h\'
credit for the original answer to
http://blog.pagebakers.nl/2009/01/29/git-ignoring-changes-in-tracked-files/
Be sure that your actual repo is the lastest version
- Edit
.gitignore
as you wish
git rm -r --cached .
git add .
then commit as usual
Old question, but some of us are in git-posh
(powershell). This is the solution for that:
git ls-files -ci --exclude-standard | foreach { git rm --cached $_ }