1

I've have directory structure like :

a
|-- b
|   |-- qfq.txt
|   |-- ewfw.txt
|   | ...
|
|-- c
|   |-- wgfw.txt
|   |-- wjkh.txt
|   | ...
| ...

I need to gitignore all txt files in a/*/ . I tried /a/*/*.txt and /a/**/*.txt, but they don't work.

Please help. Thank you.



Updated : Solved

/a/**/*.txt works. Also, I came to know that git doesn't commit empty folders, not knowing which I thought the commands not working properly.

Thanks @JonathonReinhar, @phd, pankaj for quick response.

Community
  • 1
  • 1
  • Why not use additional `.gitignore` files in those directories? It's much simpler. – Jonathon Reinhart Jan 19 '20 at 13:13
  • In what way they don't work? Were the files already committed? – phd Jan 19 '20 at 13:22
  • @JonathonReinhart Yes. This will be simpler. The reason I'm avoiding this is because the above structure is quite redundant in my project structure and I was thinking of a central control on gitignore. – Somesh Jaiswal Jan 19 '20 at 13:34
  • @phd The files were not committed. On including /a/*/*.txt or /a/**/*.txt in .gitignore, it stops tracking txts at /a/* which is right. But, suppose when I push this structure to remote repo, it should push /a/* without containing txt files, which is not happening here. If a directory is empty after ignoring txts, it doesn't push directories to remote repo. – Somesh Jaiswal Jan 19 '20 at 14:04
  • `git` doesn't track empty directories. See https://stackoverflow.com/q/115983/7976758 – phd Jan 19 '20 at 14:14
  • @phd yes. got it. thanks. – Somesh Jaiswal Jan 19 '20 at 14:19

1 Answers1

1

adding this in your .gitignore should do -

$ cat .gitignore 
a/**/*.txt

Check this, I created the same directory and files structure

$ find . -name *.txt 
./a/c/wjkh.txt
./a/c/wgfw.txt
./a/b/qfq.txt
./a/b/ewfw.txt

but my "git status" is clean

$ git status
On branch master
nothing to commit, working tree clean

Make sure you first commit the .gitignore to the repo then only it will start ignoring files.

Hope this helps

Pankaj Saini
  • 1,493
  • 8
  • 13