views:

2670

answers:

4

I have an already initialized git repo that I added a .gitignore file to, how can I refresh the file index so the files I want ignored get ignored?

+1  A: 

If the files are already in version control you need to remove them manually.

Aragorn
+16  A: 

Just got the answer from the IRC channel.

Running command:

git rm -r --cached .

This removes everything from the index, then just run:

git add .

Commit it:

git commit -m ".gitignore is now working"
trobrock
be aware to commit all your changes before, otherwise you will loose control on all the changed files
sfa
This doesn't seem to stay on a push or a clean clone. any ideas?
BenB
+10  A: 

Yes - .gitignore system only ignores files not currently under version control from git. I.e. if you've already added a file called test.txt using git-add, then adding test.txt to .gitignore will still cause changes to test.txt to be tracked. You would have to git-rm test.txt first, commit that change. Only then will changes to test.txt be ignored.

Antony Stubbs
+2  A: 

To untrack a file that has already been added/initialized to your repository, ie stop tracking the file but not delete it from your system use: git rm --cached filename

pagetribe