4

My .gitignore looks more less like this:

# Ignore everything
*

# But not these files...
!.gitignore
!ImportantDirectory/
!AnotherImportantDirectory

# Actually, ignore these...
ImportantDirectory/NotImportantFile

The problem is that ImportantDirectory/NotImportantFile is still being tracked. Any idea how to solve this?

jub0bs
  • 60,866
  • 25
  • 183
  • 186
mpiekarz
  • 271
  • 4
  • 15

2 Answers2

3

If you had previously included that file, it will continue to be tracked until you remove it from your repository, even if you list it in a .gitignore. Sounds like that is what is happening here. You can do that with:

git rm --cached ImportantDirectory/NotImportantFile

Note this will remove the file from the .git repository, but will not delete the local file on disk. Note however this will delete ImportantDirectory/NotImportantFile for anyone who pulls your git repository, so if this is a file they also need to maintain, but not have included, you may need to take a different approach.

Duncan Babbage
  • 19,972
  • 4
  • 56
  • 93
0

You can't ignore paths which are already tracked. To fix this, simply move NotImportantFile somewhere else, git rm it, commit that, then move the file back in place. Now it will be properly ignored.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436