Whitelist nested files and folders using .gitignore

心不动则不痛 提交于 2019-12-23 23:40:37

问题


I want to exclude entire android/ & ios/ folder

And I want to include the following files in it:

android/settings.gradle
android/app/build.gradle
android/build.gradle
android/app/src/main/java/com/reactnativegoogleadmob/MainApplication.java

ios/Podfile
ios/ReactNativeGoogleAdmob/AppDelegate.h
ios/ReactNativeGoogleAdmob/AppDelegate.m

So my .gitignore is:

# Remove following directories

android/*
ios/*

# Add following files

!android/settings.gradle
!android/app/build.gradle
!android/build.gradle
!android/app/src/main/java/com/reactnativegoogleadmob/MainApplication.java

!ios/Podfile
!ios/ReactNativeGoogleAdmob/AppDelegate.h
!ios/ReactNativeGoogleAdmob/AppDelegate.m

But it only includes top level files like:

android/settings.gradle
android/build.gradle
ios/Podfile

I also tried android/**/* & ios/**/* but it gives same results as android/* & ios/*.

How do I include the rest of the files? I tried other solutions too but hitting a roadblock.


回答1:


I managed to make this thing work thanks to @axiac's answer here.

Read it before reading the solution below as it explains much better than I can explain -

android/*

!android/build.gradle
!android/settings.gradle

!android/app/
android/app/*
!android/app/build.gradle
!android/app/src
android/app/src/*
!android/app/src/main
android/app/src/main/*
!android/app/src/main/java
android/app/src/main/java/*
!android/app/src/main/java/com
android/app/src/main/java/com/*
android/app/src/main/java/com/reactnativegoogleadmob/*
!android/app/src/main/java/com/reactnativegoogleadmob
!android/app/src/main/java/com/reactnativegoogleadmob/MainApplication.java

ios/*

!ios/Podfile

!ios/ReactNativeGoogleAdmob/
ios/ReactNativeGoogleAdmob/*
!ios/ReactNativeGoogleAdmob/AppDelegate.h
!ios/ReactNativeGoogleAdmob/AppDelegate.m



回答2:


Your .gitignore file should have only these entries as it will ignore the files recursively inside android and ios directory.

.gitignore

android
ios


来源:https://stackoverflow.com/questions/56222119/whitelist-nested-files-and-folders-using-gitignore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!