git 忽略指定类型的文件,使用.gitignore忽略除特定目录以外的所有内容

My issue is that I have a bunch of WordPress websites in my git repo, of which I want to selectively commit only the content of my themes folders, while ignoring the rest of the redundant files found in WordPress.

I've used .gitignore files to ignore file types before, but can it be used the other way around- that is to ignore everything BUT a certain folder path?

root (git repo)

- / wordpress

- - / (WordPress Site 1)/wp-content/themes

- - / (WordPress Site 2)/wp-content/themes

- - / (WordPress Site 3)/wp-content/themes

Thanks-

UPDATE:

Based on the answers I did the following, but it's not working. Any ideas?

# Ignore everything:

*

# Except for wordpress themes:

!*/wp-content/themes/*

I've also tried the following variations:

!*/wp-content/themes*

!*wp-content/themes/*

!wp-content/themes/*

!/wordpress/*/wp-content/themes*

!wordpress/*/wp-content/themes*

None of these read my themes folders.

解决方案

Here's how I did it - you essentially have to walk up the paths, you can't wildcard more than one level in any direction:

# Ignore everything:

*

# Except for the themes directories:

!wordpress/

!wordpress/*/

!wordpress/*/wp-content/

!wordpress/*/wp-content/themes/

!wordpress/*/wp-content/themes/*

!wordpress/*/wp-content/themes/*/*

!wordpress/*/wp-content/themes/*/*/*

!wordpress/*/wp-content/themes/*/*/*/*

!wordpress/*/wp-content/themes/*/*/*/*/*

Notice how you have to explicitly allow content for each level you want to include. So if I have subdirectories 5 deep under themes, I still need to spell that out.

This is only how it worked for me. If someone cares to offer a more informed explanation by all means.

NOTE: I tried using double-wildcard 'globs' but according to this that functionality is system dependent and it didn't work on my mac:

Did NOT work:

!**/wp-content/themes/

!**/wp-content/themes/**

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值