Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set .gitignore to ignore all .jars but not in the expected folder

Tags:

git

gitignore

I have a project structure like this:

/proj/a/file.jar
/proj/a/1/file.jar
/proj/b/file.jar
/proj/b/1/file.jar
/proj/b/2/1/file.jar
/proj/c/file.jar
/proj/c/1/file.jar
/proj/c/2/1/file.jar

etc.

I'm trying to ignore all jar files except those in c folder and all nested ones. How should I set this in .gitignore?

*.jar
!c/*.jar

doesn't work. This too:

*.jar
!c/*/*.jar

and this:

*.jar
!/proj/c/*/*.jar

and this:

*.jar
!/proj/c/**/*.jar

Am I miss something?

like image 570
L'sync Avatar asked Dec 24 '12 12:12

L'sync


People also ask

How do I ignore a .gitignore file?

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a .gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.

Does Gitignore location matter?

gitignore files apply only to the files under the directory where they are located. The Linux kernel source repository has 206 . gitignore files. This is far more descriptive than "you may put it anywhere'.

How do I ignore a file without adding to Gitignore?

You just need to add the file to . git/info/exclude in the same way you would add it to . gitignore .


1 Answers

Git does not support a **-style wildcard so you can either use full paths (i.e. /whatever/*/*/*.jar etc.) for to reflect the correct amounts of directory levels or you can simply put .gitignore files containing !*.jar inside the folders where you want to unignore JAR files.

like image 152
ThiefMaster Avatar answered Oct 14 '22 21:10

ThiefMaster