gitignore重要技巧
问题:在某个开发项目中,我用gitignore指定需要git的文件,但突然新增一个子目录,而这子目录下,有非常多的子目录和各级目录还有各种不同的格式的文件,按照原来的方法,一个个添加.gitignore文件非常的麻烦,而且容易出错,又耗时?解决方案:将.gitignore文件其用途,反过来用,原来只限定上传的文件,现在只限定不上传的文件比如说:原来:*!.py!main_d...
·
问题:在某个开发项目中,我用gitignore指定需要git的文件,但突然新增一个子目录,而这子目录下,有非常多的子目录和各级目录还有各种不同的格式的文件,按照原来的方法,一个个添加.gitignore文件非常的麻烦,而且容易出错,又耗时?
解决方案:
将.gitignore文件其用途,反过来用,原来只限定上传的文件,现在只限定不上传的文件
比如说:
原来:
*
!.py
!main_dir/
修改:
test/
ess/
.gitignore要学会正反都拿来用,然后根据实际情况来处理,思维方式转换非常节约时间且高效。
Double Asterisk
** can be used to match any number of directories.
**/logs matches all files or directories named logs (same as the pattern logs)
**/logs/*.log matches all files ending with .log in a logs directory
logs/**/*.log matches all files ending with .log in the logs directory and any of its subdirectories
** can also be used to match all files inside of a directory, so for example logs/** matches all files inside of logs
比如说我要过滤各个目录下的所有__pycache__文件夹
在.gitignore文件中添加
**/__pycache__
过滤掉所有的某种类型的文件,如图所示:
仅仅使用:*.csv就可以了,就可以匹配任何目录下的csv文件。如果只想匹配当前目录下的需要加个/*.csv
更多推荐
已为社区贡献4条内容
所有评论(0)