【发布时间】:2012-04-02 14:34:00
【问题描述】:
我已经尝试过 Stackoverflow 上一个关于如何忽略文件的问题的建议:Ignore files that have already been committed to a Git repository
建议:
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")
谢谢你,
提姆
【问题讨论】:
-
在您执行
add .和commit之前,git status报告是什么? -
嗨阿里,请看上面修改后的问题,谢谢!
-
您已修改文件。试试
git checkout -- application/config/config.php -
嗨 mschonaker,感谢您的意见,下面关于使用
git update-index --assume-unchanged <filename>的答案对我有用,