5

my issue is not the same as Why doesn't gitignore work in this case? nor .gitignore is not working

files/conf.php is already in .gitignore, but git status still shows its modification, why?

i mean this file should not be tracked if it is in .gitignore...

cat .gitignore
files/conf.php
[root@home blogmi]# 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:   files/conf.php
#
no changes added to commit (use "git add" and/or "git commit -a")
Community
  • 1
  • 1
thinke365
  • 1,305
  • 3
  • 14
  • 22

1 Answers1

11

.gitignore only ignores untracked files. Once you've started tracking a file (as you've done with files/conf.php), it will not be ignored.

You can use git rm --cached files/conf.php to delete the file from git without actually deleting it from the filesystem. After you commit that, the file will start being ignored properly.

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347
  • exactly. From what I understand, you've already at one point 'added' and staged the file to be ready for a commit. Even if you add it to the .gitignore it wont be ignored until you run the command @KevinBallard suggested above. Then, it will not be included. – d-_-b Sep 14 '12 at 20:54
  • One question I have is, if you unstage the file, and add it to the .gitignore...If you then say `git add ` will it add it? – d-_-b Sep 14 '12 at 20:54
  • 2
    @iight: It's not staged for commit. The file is actually already committed and tracked by the repo, but contains unstaged changes. Not that it matters much. And in your second question, `git add` will actually ignore the file (and I believe it will tell you that it skipped the file). You have to use `git add -f $file` to make it work. – Lily Ballard Sep 14 '12 at 20:56