Sam
Sam

Reputation: 6552

Ignoring files in a directory, but not the directory itself, in Git

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?

Upvotes: 1

Views: 178

Answers (3)

Tim
Tim

Reputation: 6509

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?

Upvotes: 0

Vinay Aggarwal
Vinay Aggarwal

Reputation: 1585

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.

Upvotes: 0

manojlds
manojlds

Reputation: 301097

Simplest way would be to add a .gitignore within the directory and add the files to ignore in it.

Upvotes: 1

Related Questions