Naguib Ihab
Naguib Ihab

Reputation: 4506

git ignore file but not folder with the same name

My code structure is:

.gitignore
my-service << this is a file without an extention
charts
| my-service << this is a folder
| | file1
| | file2

When I write in my gitignore my-service it ignores both my-service the file and my-service the folder. How can I ignore only the file in the root directory, and not the sub-directory?

Upvotes: 18

Views: 3746

Answers (1)

Yu Jiaao
Yu Jiaao

Reputation: 4724

you can do the reverse way with! in .gitignore

myservice
!myservice/

Upvotes: 35

Related Questions