Git选择性地忽略gitignore文件

时间:2013-10-11 17:03:00

标签: git gitignore

所以,我已经设置了我的全局.gitignore文件来忽略.iml结尾的所有文件。但是,出于某种原因,它并没有忽略一个特定的iml文件。我有我的忽略文件和

~/projects/dhub
calebsutton$cat /home/calebsutton/.gitignore
*.iml

~/projects/dhub
calebsutton$git status
# On branch DM-481
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   app/web/src/main/java/com/wellcentive/integration/page/sourcetype/SourceTypeActionPage.java
#   new file:   app/web/src/main/java/com/wellcentive/integration/page/sourcetype/SourceTypeListPage.java
#   new file:   app/web/src/main/java/com/wellcentive/integration/page/sourcetype/grid/SourceTypeListGrid.java
#
# 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:   app/web/src/main/java/com/wellcentive/integration/page/sourcetype/grid/SourceTypeListGrid.java
#   modified:   app/web/web.iml
#

1 个答案:

答案 0 :(得分:7)

运行命令:

git ls-files --others | grep web.iml

在未跟踪文件列表中查找该特定文件。如果它不在该列表中,那么你需要解开它。

(相信jthill为此)

git ls-files -ic --exclude-standard

也会执行第一个命令。

此时运行:

git rm --cached app/web/web.iml

这将从您的跟踪文件列表中删除web.iml文件,而不将其从目录中删除。