有没有办法设置远程特定的 .gitignores?

发布于 2024-08-24 23:42:57 字数 268 浏览 5 评论 0原文

有没有一种简单的方法可以为不同的遥控器设置不同的 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

弱骨蛰伏 2024-08-31 23:42:57

不要将数据库信息放在database.yml中。相反,请使用 Heroku 环境变量。

Do not put database information in database.yml. Instead, use Heroku environment variables.

愛放△進行李 2024-08-31 23:42:57

我对 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 and for-repo-B. The only difference between the two branches would be the commits touching file-for-repo-B; the branch for-repo-B would always merge from master (but never the other way around!). Now you just have a different branch checked out in repo B, and all is good.

满天都是小星星 2024-08-31 23:42:57

您应该对以下版本进行版本控制:

  • database.yml,其中仅包含变量,并且
  • 脚本能够根据 database.yml 所在的远程服务器,用正确的值替换这些变量。已部署。

然后,您将该脚本用作 涂抹属性过滤器驱动

涂抹内容过滤器

每次您将在远程服务器上签出(并创建工作树),执行脚本并将相应地更改变量,为您提供自定义 database.yml 文件。
如果其中一个远程不需要该 database.yml 文件,它仍然可以在那里,但被涂抹脚本清空。

You should versionned a:

  • database.yml with only variables in it, and
  • a script able to replace those variables by the right values depending on the remote server where that database.yml is deployed.

Then you use the script as a smudge attribute filter driver:

smudge content filter

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文