Search code examples
gitgitignore

Removing a directory from .gitignore so git starts to track changes in it


I have a directory doc that was in .gitignore. I decided git should track changes in it. But after removing doc entry from .gitignore, git didn't automatically start tracking the directory.

How can I force git to watch for changes in that directory?

My second concern is, while looking for an answer to above question I found this thread: Ignore files that have already been committed to a Git repository and performed these operations:

git rm -r --cached .
git add .
git commit -m ".gitignore is now working"

I understand that it was wrong move; the above thread discussed totally opposite situation. Did I ruined something rather badly?

All this is done on a private, semi-serious project.

Thank you very much!


Solution

  • Git doesn't track directories at all, rather it tracks (file) content. It may be that you have other conditions in the .gitignore, particulalrly a !dir which then, as an optimisation in recent versions, no longer reads further gitignore files in any lower directories.

    The gitignore capability is a powerful tool, but has traps for the unwary.