GIT-如何从跟踪中删除本地文件,但将副本保留在远程存储库中? [英] GIT - How to remove local file from tracking, but leave copy on remote repository?

查看:71
本文介绍了GIT-如何从跟踪中删除本地文件,但将副本保留在远程存储库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Rails应用程序中,我有以下情形,但是该情形可以应用于任何其他应用程序,在这些应用程序中,您不想将开发凭据推送到Github这样的公共存储库中.

所以我有文件 config/database.yml ,我在这里有我的本地MySQL数据库凭据,并且我真的不想将此细节公开,所以想法是有一个副本,例如带有虚假数据的初始 database.yml ,然后将其推送到远程存储库,将其添加到.gitignore,然后将其从跟踪中删除,然后仅使用实际数据库凭据在本地存储库中更新此文件.在我这样做之后:

git rm --cached config/database.yml ,实际上已从我的远程存储库中删除了文件.我该如何防止这种情况,并在推送初始配置文件后将其忽略,而将此文件的初始提交保留在远程存储库上?

我的.gitignore有这一行来忽略文件 config/database.yml

 #忽略config/database.yml/config/database.yml 

长话短说,我想在本地和远程存储库中拥有两个不同的文件副本,并且一旦我将使用实际的MySQL更新 database.yml 文件时,我就不想跟踪更改.服务器连接凭据.

解决方案

请不要将 database.yml 提交到版本控制.将其添加到 .gitignore

请提交一个名为 example.database.yml 的副本,其中包含一些虚拟值.然后,您的部署过程将复制示例并替换秘密值.

否则,您将陷入维护噩梦,即忽略配置文件,然后在需要进行框架更改时暂时将其忽略,并始终隐藏着意外向版本控制提交密码的危险.

I have a following scenario, in my Rails app, but scenario can be adopted to any other application, where you don't want to push your development credentials to public repository like Github.

So I have file config/database.yml, where I have my local MySQL database credentials, and I don't really want to push this details to public, so idea is to have one copy, for example initial database.yml with dummy data, then push it to remote repository, add it to .gitignore, and remove it from tracking, and then update this file just in local repo with actual database credentials. After I did this with:

git rm --cached config/database.yml, file actually was deleted from my remote repository. How can I prevent this, and after I push initial config file, ignore it, but leave initial commit of this file on remote repo?

My .gitignore has this line to ignore file config/database.yml

# Ignore config/database.yml
/config/database.yml

Long story short, I want to have two different copies of file in my local and remote repository, and I don't want to track changes once I will update database.yml file with actual MySQL server connection credentials.

解决方案

Never commit database.yml to version control. Add it to .gitignore

Instead commit a copy called example.database.yml with some dummy values. Then your deploy process copies the example and substitutes the secret values.

Otherwise you'll be stuck in a maintenance nightmare of ignoring the config file and then temporarily un-ignoring it when you need to make framework changes, and always lurking the danger of accidentally committing a password to version control.

这篇关于GIT-如何从跟踪中删除本地文件,但将副本保留在远程存储库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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