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
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
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
.
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.
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).
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?
.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.