Search code examples
gitgitignore

gitignore particular file format in all directories


I want to exclude a file format e.g *.simg in all directories. I have tried to add *.simg in .gitignore but still the files are visible in git status.

I have a folder structure as follow and .gitignore file is in root directory:

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

How can I exclude the format in all directories?

EDIT 1:

.gitignore file as follow:

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

### SINGULARITY simg###
*.simg

When I do git status I get:

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")

Solution

  • What you have done in your .gitignore is correct. You need to remove the files from the staging area by doing a git rm -r --cached <filename/pathspec> and then commit the changes. When there will be any changes in the files next time, they won't cause trouble :)

    You might want to refer to this as well.

    Best