是否可以根据环境变量使.gitignore可配置? [英] Is it possible to make .gitignore configurable based on environment variables?
问题描述
是否可以添加.gitignore规则取决于环境变量?
Is it possible to add to .gitignore rules depends on environment variables?
例如
if -e $(ENV_VAR) "AAA"
!liba.so
else
liba.so
基本上我想要的是拥有一个存储库,使得如果ENV_VAR ="AAA"
,本地存储库将具有 a.txt
和 ENV_VAR
未设置a.txt将被删除.
Basically what I want is to have a repository such that if ENV_VAR = "AAA"
the local repository will have a.txt
and if ENV_VAR
isn't set the a.txt will be removed.
推荐答案
当前答案为否是,但不使用环境变量.
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.
假设我将我的超级秘密密码添加到 src/assets/secrets.xml
文件中,以便可以在本地运行代码,但是我从不希望密码泄露给github,这样我就可以可以使用此之类的工具找到.
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.
最初,我认为能够导出GITIGNORE = path/to/that/file
的功能在这种情况下会有所帮助.
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
在重新阅读了OP的问题几次之后,我不确定这是否能满足他的要求.
After re-reading the OP's question a couple of times, I'm not sure if this will do what he's asking.
这篇关于是否可以根据环境变量使.gitignore可配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!