GIT - How to remove local file from tracking, but leave copy on remote repository?

人走茶凉 提交于 2021-02-11 05:57:47

问题


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.


回答1:


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.




回答2:


You can use

git update-index --assume-unchanged config/database.yml

to ignore local changes to a tracked file.



来源:https://stackoverflow.com/questions/40410267/git-how-to-remove-local-file-from-tracking-but-leave-copy-on-remote-repositor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!