我用以下几行设置了.gitignore
文件
这有效:
application/cache/*
!application/cache/index.html
但这不起作用:
web/uploads/*
!web/uploads/filters/.gitkeep
!web/uploads/payments/.gitkeep
!web/uploads/surveys/.gitkeep
没有/web/uploads
或web/uploads/filters/.gitkeep
,web/uploads/payments/.gitkeep
或web/uploads/surveys/.gitkeep
文件。
答案 0 :(得分:0)
有效规则与无效规则之间存在很大差异。那些工作在目录和其中的文件上的文件。无效的目录包含中间目录。
web/uploads/*
此忽略规则告诉Git忽略web/uploads
的所有文件和子目录。
遵循的排除规则:
!web/uploads/filters/.gitkeep
!web/uploads/payments/.gitkeep
!web/uploads/surveys/.gitkeep
与任何文件都不匹配,因为filters
,payments
和surveys
目录(及其内容)由于先前的规则而被忽略。
没有解决此问题的简单方法(或者,至少我没有意识到)。
存在一个解决方案(但很冗长):您必须告诉Git忽略web/uploads
,filters
和payments
子目录之外的surveys
中的所有内容,让每个人都忽略.gitkeep
之外的所有内容。
按照.gitignore
的规则,以上段落表示如下:
# Ignore everything in web/uploads
web/uploads/*
# ... except for the 'filters' subdirectory...
!web/uploads/filters
# ... but ignore everything inside it...
web/uploads/filters/*
# ... except for .gitkeep
!web/uploads/filters/.gitkeep
# The same rules as above for 'payments'
!web/uploads/payments
web/uploads/payments/*
!web/uploads/payments/.gitkeep
# ... and surveys
!web/uploads/surveys
web/uploads/surveys/*
!web/uploads/surveys/.gitkeep