使用 github 托管公共 git 存储库,同时确保敏感数据文件不被跟踪

发布于 2024-08-21 00:12:10 字数 854 浏览 8 评论 0原文

我的应用程序托管在 Heroku 上,并且我也有一个公共 github 存储库。

我的应用程序有一个配置文件,其中包含我的亚马逊 S3 凭据。重要的是要确保文件被推送到 heroku 而不是 github。

所以我想我可以将我的主分支推送到heroku并创建一个单独的github分支并确保它的.gitignore文件引用我的s3.yml文件。然后我可以执行“git push origin github:master”将 github 分支推送到 github.com

这对于第一次提交来说效果很好。

但后来我切换到主分支,编写一些很棒的代码,然后将其全部推送到 heroku。然后我切换回我的 github 分支并执行“git merge master”,以便将新代码添加到其中。但这会导致 master 分支中的 s3.yml 和 gitignore 文件被复制到 github 分支中。提示头对桌敲击会议。

对于保持分支同步同时确保未跟踪的文件保持未跟踪的方法有什么建议吗?我可以告诉 git 不要合并不需要的 S3.yml 文件和不同的 .gitignore 文件吗?

我这是在鞭打死马吗?我还不能证明为私人 github 帐户付费是合理的,但我想答案将涉及这样做......或者切换到 Projectlocker

我希望这个问题只是因为我的垃圾 git 技能,并且有一个方式....提前致谢

编辑::: 接受的答案是一个很好的解决方案,但我刚刚找到了一个我更喜欢的新答案。在这里阅读:http://docs.heroku.com/config-vars - 那些聪明的人Heroku 的人们对一切问题都有答案……真的太棒了

My app is hosted on Heroku and I have a public github repo too.

My app has a config file containing my amazon S3 credentials. It's important to ensure that the file gets pushed to heroku but not github.

So I was thinking that I could push my master branch to heroku and create a seperate github branch and ensure that it's .gitignore file references my s3.yml file. I could then just do "git push origin github:master" to push the github branch to github.com

This works fine for the first commit.

But then I switch to my master branch, write some awesome code and then push it all to heroku. I then switch back to my github branch and do "git merge master" so that the new code gets added to it. But this causes the s3.yml and gitignore files from the master branch to get copied into the github branch. Cue head-to-desk banging session.

Is there any advice on ways to keep branches synched up whilst ensuring that untracked files remain untracked. Can I tell git not to merge in the unwanted S3.yml file and the different .gitignore file?

Am I flogging a dead horse here? I can't justify paying for a private github account yet but I imagine the answer will involve doing just that.... or switching to projectlocker

I'm hoping that this problem is just down to my crap git skills and that there is a way.... thanks in advance

EDIT::: The accepted answer is a great solution, but I've just found a new one that I like much more. Read about it here: http://docs.heroku.com/config-vars - those clever people at Heroku have an answer for everything... seriously awesome

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

旧街凉风 2024-08-28 00:12:10

但这会导致 master 分支中的 s3.yml 和 gitignore 文件被复制到 github 分支中

您可以使用自定义合并驱动程序来避免这种情况,这将确保 github 分支的 .gitignore 文件将始终保留其内容而不是从 master 合并的内容。

请参阅如何告诉 git 始终选择本地版本来进行特定文件上的冲突合并?

But this causes the s3.yml and gitignore files from the master branch to get copied into the github branch

You can avoid that with a custom merge driver which will make sure to the .gitignore file of the github branch will always retain its content over the one merged from master.

See How do I tell git to always select my local version for conflicted merges on a specific file?

忆依然 2024-08-28 00:12:10

在 SVN 中这被称为“忽略文件”,所以我认为它在 GIT 中是类似的 - 我不使用 GIT,所以不要引用我的观点,但我在 GITHub 网站上找到了这个参考:

http://github.com/guides/ignore-for-git

希望有帮助

in SVN this is called 'ignoring files' so I assume it will be something similar in GIT - I don't use GIT so don't quote me on this, but I've found this reference on the GITHub website:

http://github.com/guides/ignore-for-git

Hope that helps

冷︶言冷语的世界 2024-08-28 00:12:10

您可以将“危险”文件完全从 git 中移走 - 例如将它们放在 ~/.yourapp 或类似的东西中。 (这并没有真正直接回答问题,但它是许多软件的功能 - .fetchmail、.ssh,...)并且允许其他用户执行相同的操作。

You could maybe move the "dangerous" files away from git entirely - eg have them in ~/.yourapp or something like that. (that doesn't really answer the question directly but its what lots of software does - .fetchmail, .ssh, ...) and would permit other users to do the same.

巨坚强 2024-08-28 00:12:10

如果您使用名为 heroku 的分支作为“替代主”分支(包含敏感数据),而旧的主分支没有敏感数据,那么您始终可以这样做,

git merge master

因此您可以将 heroku 分支推送到 heroku 而不是主分支。

If you use a branch named heroku as your "alternative master" branch (with sensitive data) and your old master branch without the sensitive data, then you could always do

git merge master

So you can push heroku branch to heroku not the master branch.

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