Git extended ignore

Mine .gitignore

looks something like this:

# Ignore everything
*

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

# Actually, ignore these...
ImportantDirectory/NotImportantFile

      

The problem is it ImportantDirectory/NotImportantFile

is still being tracked. Any idea how to solve this?

+3


source to share


2 answers


If you previously included this file, it will continue to be tracked until you remove it from your repository, even if you list it in .gitignore. It looks like this is what's going on here. You can do it with

git rm --cached ImportantDirectory/NotImportantFile

      



Note. This will remove the file from the .git repository, but it will not remove the local file on disk. Note, however, this will remove ImportantDirectory/NotImportantFile

for anyone pulling your git repository, so if it's a file that also needs to be maintained but not included, you may need a different approach.

+3


source


You cannot ignore the paths that are already being tracked. To fix this, simply move the file to a NotImportantFile

different location git rm

, commit it, and then move the file into place. It will now be properly ignored.



0


source







All Articles