簡體   English   中英

除了某個目錄的所有子目錄外,Git會忽略某種類型的所有文件嗎?

[英]Git ignore all files of a certain type except in all subdirectories of a certain directory?

我正在嘗試創建一個忽略所有.jar文件的gitignore文件,除非它們位於名為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 addgit 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM