tags:

views:

84

answers:

4

I add the following line to .gitignore but when I type "git status" it show the file as unstaged file.what's the problem? all other patterns work good.

.gitignore file content:

sites/default/settings.php

+2  A: 

Make sure that your .gitignore is in the root of the working directory, and in that directory run git status and copy the path to the file from the status output and paste it into the .gitignore.

edit

In response to your information in a comment below: “and result of "git status" is : "changes but not updated: modified: sites/default/settings.php".also note that file is tracked ...”

The reason to ignore files in git is so that they won't be added to the repository. You previously added the file you want to be ignored to your repository, so of course you can no longer ignore it (because git already knows about it).

So if you want to ignore the file, you have to untrack files. You can do that by using git rm --cached sites/default/settings.php. This will remove the tracking. After a commit (in which the file gets removed from the repository), the ignoring should work.

poke
What do you mean by 'root of the working directory'? The directory where the '.git' repository is found?
Jonathan Leffler
The working directory is the directory in which the `.git` directory is located and which itself is the repository's root. Like when you clone a repository to `/xy/` then `/xy/` is your working directory with `/xy/.git/` inside.
poke
thanks.it works now.
Hamid.P
A: 

Thanks for replies.but still doesn't work.my friend told maybe file(to be ignored) is added manually.if it's true how can I solve it?It seems problem is relative to the file itself(file to be ignored).

Hamid.P
Don't answer to your own question with updates, this is not a forum. Please *update* your question instead or comment to a reply. Also could you maybe make a screenshot from the `git status` and tell us the exact contents of the `.gitignore`?
poke
.gitignore file only consist of "sites/default/settings.php" and result of "git status" is : "changes but not updated: modified: sites/default/settings.php".also note that file is tracked...Now I'm sure the problem is relative to the file.what may be cause a file or folder not to be ignored?
Hamid.P
Ah, okay. See my updated answer for instructions how to resolve this.
poke
+1  A: 

I just tried this with git 1.7.3.1, and given a structure like:

repo/.git/
repo/.gitignore
repo/sites/default/settings.php

where repo thus is the "root" mentioned above (I would call it the root of your working tree), and .gitignore contains only sites/default/settings.php, the ignore works for me (and it does not matter whether .gitignore is added to the repo or not). Does this match your repo layout? If not, what differs?

Johan
Yes.it's exactly the same as yours.but not works.all other patterns work.As I said problem is surely relative to settings.php folder.
Hamid.P
+1  A: 

.gitignore will only ignore files that you haven't already added to your repository.

If you did a git add ., and the file got added to the index, .gitignore won't help you. You'll need to do git rm sites/default/settings.php to remove it, and then it will be ignored.

jonescb
thanks.but How do I remove the file only from index and not from working directory?
Hamid.P
`git rm` should do that, but it may be asking you to use the -f option which would remove it from the working directory. I haven't figured this out other than to make a copy of the file, do `git rm -f` and then restore the copy.
jonescb