2012-04-02 103 views
1

我已经尝试过什么由有关如何忽略文件以前的问题#1建议:Ignore files that have already been committed to a Git repositorygit的添加/删除承诺并不仅仅是忽略的.gitignore忽略文件

什么建议:

git rm -r --cached . 

我使用的命令:

git rm -r --cached application/config/config.php 
//i only want to ignore this one file 

不幸的是,当我做git add.然后git commit我的config.php文件是从存储库中删除了,而不仅仅是忽略。

我有一个.gitignore文件以在我的根目录下,它包含以下列表项:

application/config/config.php 

可能有人能帮助我理解为什么这个config.php文件正在删除和公正不被忽视?

这里就是我的git的状态显示:

$ 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: .gitignore 
# modified: application/config/config.php 
# 
no changes added to commit (use "git add" and/or "git commit -a") 

谢谢你,

+1

在做'add'和'commit'之前,'git status'报告是什么? – Ali 2012-04-02 14:35:52

+0

hi Ali,请参阅上面修改的问题,谢谢! – 2012-04-02 14:50:19

+0

您已修改文件。试试'git checkout - application/config/config.php' – mschonaker 2012-04-02 14:56:36

回答

3

它正在从资料库中删除,因为你删除了它。 git rm将删除该文件,并且--cached将其保留在您的工作目录中。

如果您想制作文件,您可以做git update-index --assume-unchanged <filename>,它只是从不会通知文件发生变化,但会将旧版本保留在存储库中。在这里进一步阅读:http://gitready.com/intermediate/2009/02/18/temporarily-ignoring-files.html

+0

Hi Dan,那完美的工作!我怀疑'rm'不是正确的命令,但不知道'git update-index ...'。谢谢! – 2012-04-02 14:57:37

+0

对我也很有帮助;) – 2015-08-07 07:15:53