Is it possible to make .gitignore changed according to environment variables

前端 未结 3 1617
余生分开走
余生分开走 2021-01-27 06:27

Is it possible to add to .gitignore rules depends on environment variables?

for example

if -e $(ENV_VAR) \"AAA\"
!liba.so
else
liba.so

3条回答
  •  星月不相逢
    2021-01-27 07:15

    The answer is no. Gitignore rules are static. You can turn around it by dynamically creating your .gitignore file. So, you will also have dynamically created static rules.

    This can be easily done within the application building system such a Makefile. The .gitignore file can rebuilt each time the project is built.

    Example Makefile:

    all: my_app .gitignore
    
    .gitignore: some deps
        cp my_static_gitignore_rules .gitignore
        echo 'dynamically_created_rule1' >> .gitignore
        echo 'dynamically_created_rule2' >> .gitignore
    
    my_app: my_app.c
        ...
    

提交回复
热议问题