Question

I have created a .gitignore file in the folder with the .git folder, but I still get the files I'm trying to ignore when doing a rescan of the repository.

This is the content of the file.

# Ignored files
*.suo 
*.user 
bin 
obj 
*.pdb 
*.cache 
*_svn 
*.svn 
*.suo 
*.user 
*.build-res 
TestResults 
_ReSharper*

What am I doing wrong? where is the file suppose to be located?

Was it helpful?

Solution

You need to make sure the file you are still seeing are not currently committed or staged.

If you remove them (git rm or git rm --cached), and then add them as private file, then they will be ignored.

OTHER TIPS

Your file looks good. Just make sure you don't have any kind of whitespace at the beginning of each line, it took me 4 hours to find why my .gitignore wasn't working correctly; the reason was of course a cut'n'paste issue where I had a vertical line of spaces at the beginning of the file.

You should be careful with git commit -a before making sure that your .gitignore file really cleans out everything you don't want. Either mark each file (or use wildcards) with git add *.cpp *.h or - like I prefer - develop your .gitignore as you progress, and always check with git status before commiting.

If you want to double-check that your .gitignore really works, try

git ls-files --others -i --exclude-standard

This should list all the files that you are currently ignoring.

To clean out the files you've already added (probably using git add ., a mistake we all make in the beginning =]) you can do like @VonC said: either run

git rm <filename>

or

git rm --cached <filename>

Another option of cleaning out all the files you've unintentionally added is to totally clean your repository, and then re-add everything again. If you want to clear out everything in the staging area, you can run

git --rm cached .

But remember to not run git add . Until you've made sure that git status only lists the files you really want in the repository.

Another very useful thing with git is that it doesn't need paths to files when using wildcards. If you list your ignored files and see that you want to remove all *.suo and *.log files, just run

git rm --cached *.suo *.log

and git takes care of finding all the files in your repository that matches that signature, no matter where in the tree they are.

I tried multiple ways to get this to work and it was finally pretty simple:

You must commit the .gitignore first!

Also, if you use TortoiseGIT - GitEx Commit Tool, there is an option to edit ignored files.

You are locating it right. .gitignore should be at the same folder, where is .git folder located. File inside also looks correct. However, I dont have a comment line at the top..

When I look at this, I would think you forgot to commit your ignore file.

None of the --rm cached solutions worked for me. The file needs to be encoded as ASCII/ANSI. I changed the line endings as well, but that alone didn't fix it. I can't find the url that had these instructions(sorry, original poster!) but this worked for me:

  1. Install Notepad++ if you don't have it already. Textpad should also work, but I use Notepad++.
  2. Open your .gitignore with Notepad++.
  3. Click on View | Show Symbol | Show All Characters. You will probably see CR LF at the end of each line.
  4. Do a search and replace(ctrl+h), making sure that Extended is checked(lower let hand corner). Search for \r\n and replace with \n. You'll see all the CR LF change to just LF.
  5. Now click on Encoding | Encode in ANSI.
  6. Save the file and exit.

From the command prompt in windows or the git command prompt, whichever you like, when you do git status it should not show files in .gitignore.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top