.gitignore exclude folder but include specific subfolder

后端 未结 17 1588
一个人的身影
一个人的身影 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 06:51

    I often use this workaround in CLI where instead of configuring my .gitignore, I create a separate .include file where I define the (sub)directories I want included in spite of directories directly or recursively ignored by .gitignore.

    Thus, I additionally use

    git add `cat .include`
    

    during staging, before committing.

    To the OP, I suggest using a .include which has these lines:

    /application/language/gr/*
    

    NOTE: Using cat does not allow usage of aliases (within .include) for specifying $HOME (or any other specific directory). This is because the line homedir/app1/* when passed to git add using the above command appears as git add 'homedir/app1/*', and enclosing characters in single quotes ('') preserves the literal value of each character within the quotes, thus preventing aliases (such as homedir) from functioning (see Bash Single Quotes).

    Here is an example of a .include file I use in my repo here.

    /home/abhirup/token.txt
    /home/abhirup/.include
    /home/abhirup/.vim/*
    /home/abhirup/.viminfo
    /home/abhirup/.bashrc
    /home/abhirup/.vimrc
    /home/abhirup/.condarc
    

提交回复
热议问题