John Smith
John Smith

Reputation: 1876

Git ignore only files with the same name as folder

I have this directory structure:

app/.bundle/
app/file1.bundle
app/tmp/file2.bundle
app/.gitignore

I would like to add an entry in .gitignore that only ignores files that ends with .bundle.

Doing *.bundle will also ignore the folder .bundle, but I want it checked in along with the contents.

Upvotes: 8

Views: 2717

Answers (2)

Kemin Zhou
Kemin Zhou

Reputation: 6891

If you have a directory with a file of the same name samename/samename then I believe you can add to your .gitignore file:

samename/samename

Then only the file but not the directory will be ignored. If you only have

samename 

in your .gitignore file then both the directory and the file will be ignored. In your first version the file with the same name in a different directory will not be ignored. Say differentname/samename will not be ignored. Let me know if I am wrong.

Upvotes: 0

poke
poke

Reputation: 387607

You can do this:

*.bundle
!.bundle/

This will ignore everything that ends with .bundle, except a folder that is called .bundle.

Upvotes: 18

Related Questions