有没有办法设置远程特定的 .gitignores?
有没有一种简单的方法可以为不同的遥控器设置不同的 .gitignore 文件?我有一个存储库,我将其推送到 Heroku 和 Github。我需要 Heroku 的 database.yml,但不希望将某些信息推送到 Github。所以我需要为每个遥控器使用不同的 .gitignore 文件。
我尝试有两个独立的分支,一个忽略database.yml,另一个不忽略。问题是,当我签出heroku分支并返回到我的github分支时,整个database.yml文件都消失了。
有什么建议吗?
Is there a simple way to setup different .gitignore files for different remotes? I have a repository I push up to both Heroku and Github. I need database.yml for Heroku, but don't want some of the information to be pushed up to Github. So I need a different .gitignore file for each of the remotes.
I tried having two separate branches, one that ignores database.yml, and one that doesn't. The problem is that when I checkout the heroku branch and go back into my github branch, the entire database.yml file is gone.
Any tips?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不要将数据库信息放在database.yml中。相反,请使用 Heroku 环境变量。
Do not put database information in database.yml. Instead, use Heroku environment variables.
我对 Heroku 的要求一无所知 - 希望正义是正确的,你可以简单地避免这个问题。如果你不能,或者如果其他人发现这个不能...
如果你希望两个远程成为镜像(具有相同的提交),那么根据定义,它们必须在这些提交中具有相同的文件。因此,您有两个选择:在所有存储库中都有
file-for-repo-B
,即使它们不需要它,或者使用带有两个分支的稍微混乱的工作流程:master< /code> 和
for-repo-B
。两个分支之间的唯一区别是提交涉及 file-for-repo-B ;分支for-repo-B
总是从master
合并(但绝不会相反!)。现在您只需在存储库 B 中签出一个不同的分支,一切都很好。I don't know anything about the requirements for Heroku - hopefully Justice is right and you can simply avoid the problem. If you can't, or if someone else finds this who can't...
If you want the two remotes to be mirrors (have the same commits), they must by definition have the same files in those commits. So, you have two choices: have
file-for-repo-B
in all repositories, even if they don't need it, or use a slightly messy workflow with two branches:master
andfor-repo-B
. The only difference between the two branches would be the commits touchingfile-for-repo-B
; the branchfor-repo-B
would always merge frommaster
(but never the other way around!). Now you just have a different branch checked out in repo B, and all is good.您应该对以下版本进行版本控制:
database.yml
,其中仅包含变量,并且database.yml
所在的远程服务器,用正确的值替换这些变量。已部署。然后,您将该脚本用作 涂抹属性过滤器驱动:
每次您将在远程服务器上签出(并创建工作树),执行脚本并将相应地更改变量,为您提供自定义
database.yml
文件。如果其中一个远程不需要该
database.yml
文件,它仍然可以在那里,但被涂抹脚本清空。You should versionned a:
database.yml
with only variables in it, anddatabase.yml
is deployed.Then you use the script as a smudge attribute filter driver:
Each time you will checkout (and create a working tree) on a remote server, the script is executed and will change the variables accordingly, giving you a custom
database.yml
file.If one of the remote does not need that
database.yml
file, it can still be there, but emptied by the smudge script.