0

I tried several different combinations, but I was not able to exclude the mongodb log from git.

My gitignore:

mongodb/data/
mongodb/data/log/mongod.log
mongodb/data/**/*.log
/mongodb/data/**/*.log

None of them work. When I type

git status

I still get the following:

modified: mongodb/data/log/mongod.log

How can I ignore this file? The data under mongodb/data/db is ignored. I do not understand why the log file is constantly showing up again.

reggie
  • 3,523
  • 14
  • 62
  • 97
  • 1
    possible duplicate of [Making git "forget" about a file that was tracked but is now in .gitignore](http://stackoverflow.com/questions/1274057/making-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – javierfdezg Jul 02 '15 at 15:49
  • possible duplicate of [Ignore files that have already been committed to a Git repository](http://stackoverflow.com/questions/1139762/ignore-files-that-have-already-been-committed-to-a-git-repository) – Sascha Wolf Jul 03 '15 at 10:01
  • This is one of the most frequently asked questions on the [tag:git] tag, please ensure to use the search before asking new questions. – Sascha Wolf Jul 03 '15 at 10:02

1 Answers1

6

Once you have a file in the git tree, it's not enough to add it to the .gitignore file, as it still belongs to the tree and git will take care of.

The .gitignore file is intended to be used before you add files to the tree.

In your situation you have to remove the file from the tree with:

git rm path/to/file

You also will have to commit the deletion.

If you want to keep a copy where it is at the moment, move it to /tmp, issue a git status (it should be marked as deleted), make a commit and move it again to the original place.

I'd suggest to use the global git configuration for widely used common files that are likely to be ignored in other projects. You can check out this question: Global Git ignore

javierfdezg
  • 2,087
  • 1
  • 22
  • 31