.gitignore exclude folder but include specific subfolder

后端 未结 17 1592
一个人的身影
一个人的身影 2020-11-21 06:36

I have the folder application/ which I add to the .gitignore. Inside the application/ folder is the folder application/language

17条回答
  •  盖世英雄少女心
    2020-11-21 07:15

    There are a bunch of similar questions about this, so I'll post what I wrote before:

    The only way I got this to work on my machine was to do it this way:

    # Ignore all directories, and all sub-directories, and it's contents:
    */*
    
    #Now ignore all files in the current directory 
    #(This fails to ignore files without a ".", for example 
    #'file.txt' works, but 
    #'file' doesn't):
    *.*
    
    #Only Include these specific directories and subdirectories:
    !wordpress/
    !wordpress/*/
    !wordpress/*/wp-content/
    !wordpress/*/wp-content/themes/
    !wordpress/*/wp-content/themes/*
    !wordpress/*/wp-content/themes/*/*
    !wordpress/*/wp-content/themes/*/*/*
    !wordpress/*/wp-content/themes/*/*/*/*
    !wordpress/*/wp-content/themes/*/*/*/*/*
    

    Notice how you have to explicitly allow content for each level you want to include. So if I have subdirectories 5 deep under themes, I still need to spell that out.

    This is from @Yarin's comment here: https://stackoverflow.com/a/5250314/1696153

    These were useful topics:

    • How do negated patterns work in .gitignore?
    • How do gitignore exclusion rules actually work?

    I also tried

    *
    */*
    **/**
    

    and **/wp-content/themes/**

    or /wp-content/themes/**/*

    None of that worked for me, either. Lots of trial and error!

提交回复
热议问题