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
#

运行命令:

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

以在未跟踪的文件列表中查找该特定文件。如果它不在该列表中,则需要取消跟踪它。

(为此感谢Jthill(

git ls-files -ic --exclude-standard

也执行第一个命令执行的操作。

此时运行:

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

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

最新更新