我正在尝试制作一个gitignore文件,它将忽略所有.jar文件,除非它们位于名为libs的文件夹中。这是我的基本文件结构:
-.gitignore
-libs/
-goodFile.jar
-someFolder/
-subFolder/
-alsoGood.jar
-otherCode/
-fileToExclude.jar
-otherOtherCode/
-otherSubfolder/
-alsoExclude.jar
目前在.gitignore中,我已经尝试过:
*.jar
!libs
!libs/
!libs/*
!libs/**
!libs/**/
!libs/**/*.jar
!libs/*.jar
可以自己,组合甚至一起使用。他们都不工作。我发现这样做的唯一方法是将另一个.gitignore文件放入libs/
(我希望避免)文件中,或者!libs/*/*/*.jar
对子目录的每个可能级别使用一行。有没有办法让它忽略除libs中的罐子以外的所有罐子?
怎么样:
*.jar
!libs/**/*.jar
顺序很重要。
编辑我使用了您的项目结构,并在执行了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
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句