git 忽略文件但不忽略同名文件夹

git ignore file but not folder with the same name

我的代码结构是:

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

当我在 gitignore my-service 中写入时,它会忽略 my-service 文件和 my-service 文件夹。 如何只忽略根目录下的文件,不忽略子目录下的文件?

你可以在 .gitignore

中用 ! 做相反的事情
myservice
!myservice/