为什么Git不会忽略我指定的文件? [英] Why Git doesn't ignore my specified file?

查看:87
本文介绍了为什么Git不会忽略我指定的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将下面一行添加到.gitignore中,但是当我输入git status时,它将该文件显示为非保留文件。问题是什么?所有其他模式工作良好。

.gitignore文件内容:

sites / default / settings.php

p>




感谢回复,但仍然无法正常工作。我的朋友告诉可能手动添加文件(被忽略)。这是真的我该如何解决它?看起来问题是相对于文件本身(文件被忽略)。

制作确保你的 .gitignore 位于工作目录的根目录下,并在该目录下运行 git status 从状态输出中复制文件的路径并将其粘贴到 .gitignore 中。



编辑



在下面的评论中回复您的信息:和git status的结果是:更改但未更新:修改:网站/ default / settings.php。同时注意文件被跟踪...



在git中忽略文件的原因是这样他们将不会被添加到回购sitory。您之前将您想要忽略的文件添加到您的存储库中,因此您当然不能再忽略它(因为git已经知道它)。



所以如果你想要忽略文件,你必须解开文件。你可以使用 git rm --cached 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


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

解决方案

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.

这篇关于为什么Git不会忽略我指定的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆