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

前端 未结 3 1651
余生分开走
余生分开走 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 06:51

    Currently the answer is no Yes, but not using an environment variable.

    My use case is simple; I'd like to avoid accidentally checking in changes that I've made to a specific file so I can run my code locally.

    Let's say I add my super secret password to the src/assets/secrets.xml file so that I can run my code locally, but I never want my password to leak to github so it can be found with tools like this.

    Originally I thought having the ability to export GITIGNORE=path/to/that/file would be helpful in this circumstance.

    But since that's not an option, here's how to accomplish the same goal.

    git update-index --assume-unchanged src/assets/secrets.xml
    

    To undo this effect:

    git update-index --no-assume-unchanged src/assets/secrets.xml
    

    After re-reading the OP's question a couple of times, I'm not sure if this will do what he's asking.

提交回复
热议问题