我正在尝试创建一个 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
子目录的每个可能级别的行。有没有办法让它忽略除库中的 jar 之外的所有 jar?
怎么样:
*.jar
!libs/**/*.jar
顺序很重要。
Edit我使用了你的项目结构,并在我做了之后得到了以下输出git add
and 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)