Git:如何忽略一个仓库中的文件并将其添加到另一个仓库? [英] Git: How to ignore a file from one repo and add it to another?

查看:105
本文介绍了Git:如何忽略一个仓库中的文件并将其添加到另一个仓库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要在Heroku上托管的Ruby on Rails应用程序.我还想使用GitHub公共(免费)存储库来跟踪更改.我需要检入一个包含密码的文件,该密码包含Heroku远程仓库的密码,但是请忽略该文件,因此我不会将其检入GitHub.有什么方法可以将文件添加到一个仓库中,而从另一个仓库中忽略它?

I have a Ruby on Rails application that I am trying to host on Heroku. I would also like to use a GitHub public (free) repository to track changes. I need to check-in a file containing passwords to the Heroku remote repo, but ignore the file so I don't check it in to GitHub. Is there a way I can add the file to one repo, and ignore it from another?

更新:我想出了如何使用 Heroku配置变量.但是,我仍然对仅将文件推送到指定存储库的概念感兴趣.

Update: I figured out how to solve my immediate problem of storing passwords in Heroku by using Heroku Config vars. However, I'm still interested in the concept of pushing a file to only specified repos.

推荐答案

您可以做的是将smudge脚本添加到GitHub存储库中(

What you could do is to add to the GitHub repo a smudge script (filter driver) which will:

  • 测试私人分支机构的存在
  • 从该分支签出密码文件

由于私有分支仅存在于Heroku存储库中,因此smudge脚本不会在GitHub存储库侧执行任何操作.
但是一旦推到Heroku端,如果一个钩子正在检出Heroku服务器上的工作目录,则该过滤器驱动程序将启动并生成敏感文件.

Since that private branch would only exist on the Heroku repo, the smudge script wouldn't do anything on the GitHub repo side.
But once pushed to the Heroku side, if a hook is checkouting a working directory on he Heroku server, then that same filter driver will kicks in and generate the sensitive file.

话虽这么说,最好不要在任何Git存储库中对这样的敏感文件进行版本控制,而最好将其存储在其他位置.
然后,涂抹脚本而不是测试某些Git存储库内容(例如私有分支),而是测试外部存储库(ssh ftp,Nexus存储库,在那里选择存储这些私有信息的其他任何数据参考),然后提取正确的内容并生成文件.

That being said, it is best for such a sensitive file to never be versioned in any Git repo, but rather being stored elsewhere.
The smudge script, rather than testing some Git repo content (like a private branch) would then test for an external repo (a ssh ftp, a Nexus repo, any other data referential out there where you choosed to stored those private informations), extract the right content and generate the file.

这篇关于Git:如何忽略一个仓库中的文件并将其添加到另一个仓库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆