git排除某文件的提交_Gitignore排除所有子目录中的某些文件

I have a directory called /static. There is a lot of subdirectories in it.

I need to ignore all files in all subdirectories of the /static/ directory except of .htaccess, null.jpg and index.php files.

Tell me please what is the right syntax for this operation?

/static/**

!/static/**/.htaccess

and

/static/*

!/static/*/.htaccess

don't work.

解决方案

As I mentioned in "Including specific file extension in gitignore", the main rule to remember is:

That is why any rule which ignores folders (like * or */) would make excluding any sub-files impossible.

That is why the right approach is to exclude everything except:

folders,

(then) the files you want to exclude.

If you don't exclude folders first, your files would still be ignored (because of the rule I mention above)

So add in your .gitignore:

/static/**/**

!/static/**/

!.gitignore

!.htaccess

This is tested with Git 2.4.1 and works even on Windows.

Note that with git 2.9.x/2.10 (mid 2016?), it might be possible to re-include a file if a parent directory of that file is excluded if there is no wildcard in the path re-included.

Nguyễn Thái Ngọc Duy (pclouds) is trying to add this feature:

commit 506d8f1 for git v2.7.0, reverted in commit 76b620d git v2.8.0-rc0

commit 5e57f9c git v2.8.0-rc0,... reverted(!) in commit 5cee3493 git 2.8.0-rc4.

However, since one of the conditions was "The directory part in the re-include rules must be literal (i.e. no wildcards)", you cannot use that feature here anyway.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值