[英]Git ignore all files of a certain type except in all subdirectories of a certain directory?
I'm trying to make a gitignore file that will ignore all .jar files unless they're in a folder called libs. 我正在尝试创建一个忽略所有.jar文件的gitignore文件,除非它们位于名为libs的文件夹中。 Here's my basic file structure: 这是我的基本文件结构:
-.gitignore
-libs/
-goodFile.jar
-someFolder/
-subFolder/
-alsoGood.jar
-otherCode/
-fileToExclude.jar
-otherOtherCode/
-otherSubfolder/
-alsoExclude.jar
Currently in .gitignore I've tried: 目前在.gitignore我尝试过:
*.jar
!libs
!libs/
!libs/*
!libs/**
!libs/**/
!libs/**/*.jar
!libs/*.jar
Either on their own, in combination, or even all together. 无论是单独的,组合的,甚至是所有的。 None of them work. 他们都没有工作。 The only way I've found to do it is to either put in another .gitignore file into libs/
(which I would prefer to avoid) or use a !libs/*/*/*.jar
line for every possible level of subdirectory. 我发现这样做的唯一方法是将另一个.gitignore文件放入libs/
(我宁愿避免)或者对每个可能级别的子目录使用!libs/*/*/*.jar
行。 Is there a way to make it ignore all jars except the ones in libs? 有没有办法让它忽略除libs中的所有罐子?
How about: 怎么样:
*.jar
!libs/**/*.jar
The order is important. 订单很重要。
Edit I used your project structure and have the following output after I did a git add
and git status
编辑我使用了您的项目结构,并在我执行git add
和git status
后输出以下内容
$ git stat
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: .gitignore
new file: libs/goodFile.jar
new file: libs/someFolder/subFolder/alsoGood.jar
new file: libs/someFolder/subFolder/test/anotherFolder/test.jar
$ cat .gitignore
*.jar
!libs/**/*.jar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.