Git-忽略子目录中的某些文件,但不是全部 [英] Git-ignore certain files in sub-directories, but not all

查看:94
本文介绍了Git-忽略子目录中的某些文件,但不是全部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似于以下的结构:

  / root / 
/ root / data /
/root/data/script.php
/root/data/some.json
/root/data/feature/one.json
/root/data/feature/two.json
/root/data/other-feature/one.json
/root/data/other-feature/important-script.php

我想让git忽略任何 .json 文件在'/ data / ...'路径,但'/ data /'有时包含子目录。

我的理解是,gitignore中的简单 data / *。json 只会匹配一个目录, code> * 不符合 / ,如 http://git-scm.com/docs/gitignore ,模式格式,第6项:

< blockquote>

否则,git会将该模式视为fnmatch(3)适用于FNM_PATHNAME标志的shell glob:模式中的通配符与路径名中的/不匹配。例如,Documentation / *。html与Documentation / git.html相匹配,但不匹配Documentation / ppc / ppc.html或tools / perf / Documentation / perf.html。

有没有简单的方法来做到这一点,或者我需要明确地在每个子目录中主动添加gitignore文件?

解决方案

我最近写了一篇关于这个问题的文章。请参阅此处



基本上你需要把 .gitignore *。json / data / 目录中。



UPD :因为git 1.8.4 1.8.2 )可以使用双星模式,例如 / data / ** / *。json


I have a structure similar to the following:

/root/
/root/data/
/root/data/script.php
/root/data/some.json
/root/data/feature/one.json
/root/data/feature/two.json
/root/data/other-feature/one.json
/root/data/other-feature/important-script.php

I'd like git to ignore any .json files under the '/data/...' path, but '/data/' sometimes contains sub-directories.

My understanding is that a simple data/*.json in gitignore will only match one directory, as the * doesn't match /, as stated at http://git-scm.com/docs/gitignore, "Pattern Format", bullet #6:

Otherwise, git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not match a / in the pathname. For example, "Documentation/*.html" matches "Documentation/git.html" but not "Documentation/ppc/ppc.html" or "tools/perf/Documentation/perf.html".

Is there a simple way to do this, or do I need to actively add gitignore files in each sub-directory, explicitly?

解决方案

I've written a post about such problem recently. See here.

Basically what you need is to put one .gitignore with *.json in the /data/ directory.

UPD: Since git 1.8.4 (1.8.2 if you're using msysgit) it is possible to use double-star patterns, like /data/**/*.json

这篇关于Git-忽略子目录中的某些文件,但不是全部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆