gitignore 所有目录中的特定文件格式

gitignore particular file format in all directories

我想在所有目录中排除一种文件格式,例如 *.simg。我已尝试在 .gitignore 中添加 *.simg,但文件在 git status 中仍然可见。

我的文件夹结构如下,.gitignore 文件在根目录中:

-service-foo/foo.simg
-service-bar/bar.simg
-composite-service/service-foobar/foobar.simg
-.gitignore

如何排除所有目录中的格式?

编辑 1:

.gitignore 文件如下:

HELP.md
target/
.mvn/
.mvn/wrapper/maven-wrapper.jar
!**/src/main/**
!**/src/test/**

### SINGULARITY simg###
*.simg

当我 git status 我得到:

javaadmin@THNJAVA11:~/server/airadhi-server$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   .gitignore
        modified:   composite-service/foobar.simg
        modified:   composite-service/service-foobar/foobar.recipe
        deleted:    service-foo/foo.simg
        modified:   service-bar/bar.simg

no changes added to commit (use "git add" and/or "git commit -a")

您在 .gitignore 中所做的是正确的。您需要通过执行 git rm -r --cached <filename/pathspec> 从暂存区中删除文件,然后提交更改。等下次文件有改动的时候,不会惹麻烦:)

您可能还想参考 this

最佳