.gitkeep文件在推送后不存在

时间:2018-07-04 11:57:55

标签: git

我用以下几行设置了.gitignore文件

这有效:

application/cache/*
!application/cache/index.html

但这不起作用:

web/uploads/*
!web/uploads/filters/.gitkeep
!web/uploads/payments/.gitkeep
!web/uploads/surveys/.gitkeep

没有/web/uploadsweb/uploads/filters/.gitkeepweb/uploads/payments/.gitkeepweb/uploads/surveys/.gitkeep文件。

1 个答案:

答案 0 :(得分:0)

有效规则与无效规则之间存在很大差异。那些工作在目录和其中的文件上的文件。无效的目录包含中间目录。

web/uploads/*

此忽略规则告诉Git忽略web/uploads的所有文件和子目录。
遵循的排除规则:

!web/uploads/filters/.gitkeep
!web/uploads/payments/.gitkeep
!web/uploads/surveys/.gitkeep

与任何文件都不匹配,因为filterspaymentssurveys目录(及其内容)由于先前的规则而被忽略。

没有解决此问题的简单方法(或者,至少我没有意识到)。

存在一个解决方案(但很冗长):您必须告诉Git忽略web/uploadsfilterspayments子目录之外的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