PortMan
PortMan

Reputation: 4523

.gitignore is not ignoring files in directory

I am trying to get git to ignore the .chef directory and everything underneath it. Here's the contents of what should be overkill in my .gitignore

/d/code/chef$ cat .gitignore
.chef
.chef/
.chef/*
.chef/**
/.chef
/.chef/
/.chef/*
/.chef/**

But this doesn't work:

/d/code/chef$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   .chef/trusted_certs/chef_am_hexagonmetrology_com.crt

What am I doing wrong?

Upvotes: 0

Views: 121

Answers (2)

Joe Phillips
Joe Phillips

Reputation: 51120

See how it says "modified"? That's because it was already committed. That means that it's already being "tracked". Once a file is tracked, the gitignore no longer applies. In order to get rid of it, you can delete it, commit that delete, and then it will no longer show up.

Or as wogsland said, you can just remove the file(s) from the index using git rm -rf --cached xxxxx

Upvotes: 4

wogsland
wogsland

Reputation: 9508

You were already tracking the .chef directory and files in it before you gitignored it. You need to stop tracking those files by

git rm -rf --cached .chef

which will remove them from tracking but not remove them from the .chef directory. See the git rm documentation for complete details.

Upvotes: 2

Related Questions