How do I ignore files in a specific directory, but not the directory itself, in Git? I can add a line to the .gitignore file, but it'll ignore the entire directory. What sort of syntax does .gitignore support in order to achieve what I want?
Asked
Active
Viewed 165 times
1
-
1What behaviour are you looking for? What do you expect Git to do with the directory if you've ignored all the files in it? Git doesn't track directories. – Tim Nov 08 '12 at 04:22
-
I expect it to create the directory in the repo. When I clone from the repo, the directory should be there, but empty. – Sam Nov 08 '12 at 05:15
-
Git doesn't store empty directories, sorry. Nothing you put into your gitignore will have any affect. – Tim Nov 08 '12 at 05:16
3 Answers
1
Simplest way would be to add a .gitignore
within the directory and add the files to ignore in it.

manojlds
- 290,304
- 63
- 469
- 417
0
You can use any of these
dir/*
- It ignores all the files in dir
directory but not it's sub directories.
dir/**
It ignores all the files in dir
direcotory and it's subdirectories.

Vinay Aggarwal
- 1,565
- 1
- 10
- 19
0
This is all about how git handles empty directories, and actually has nothing to do with .gitignore
(other than the fact that it's the ignore file that is causing you to have an empty directory)
See here How can I add an empty directory to a Git repository?