问题描述
我在github上使用smartgit。
我的远程github仓库上有一个 config.json 文件,带有隐藏密码,位于应用程序的根目录。
我需要使用真实密码在本地软件仓库中保留一个不同的 config.json 文件。
只要我尝试在本地忽略 config.json ,有时,它仍记录为“已修改”
有时,当它最终被忽略时,通过右键单击/忽略,它说1'staged', config.json 最终在推动提交时被从Github中删除,我不明白为什么:
.DS_Store
/config.json
config.json
node_modules
/uploads
/node_module
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
我的 config.json 文件,其中的空白我需要保留在Github上,因为 Heroku需要它:
{
"localhost_db": "mongodb://localhost:27017/","mongoDb_atlas_db": "mongodb+srv://jose:x@cluster0-6kmcn.azure.mongodb.net/vue-starter-webpack?retryWrites=true&w=majority","dev": false,"db_name": "vue-starter-webpack","ftp_config": {
"host": "ftpupload.net","user": "epiz_26763901","password": "x","secure": false
},"node_file_path": "./tmp/files/","cloudinary_token": {
"cloud_name": "ddq5asuy2","api_key": "354237299578646","api_secret": "x"
},"logs_path": "tmp/logs/logs.txt"
}
有什么解决方法吗?我已经尝试了很多东西。 “上演”是什么意思?如何在github和本地上保留文件的不同版本?
编辑:我正在尝试此命令,它似乎可以工作! :
git update-index --assume-unchanged config/database.yml
Ignore modified (but not committed) files in git?
解决方法
我的远程GitHub仓库上有一个
config.json
文件,带有隐藏密码,位于应用程序的根目录。
那不是一个好习惯。如果该文件(config.json
)包含任何敏感信息,则应不添加/提交该文件,但应将其明确忽略。
您可以提交的是config.json.tpl
,这是一个模板文件(实际上是您的config.json
现在的文件)
从那里,您可以在本地生成正确的config.json文件,并自动在git clone
/ git checkout
上生成文件。
生成脚本将:
- 从外部安全引用(如文件库)中搜索正确的密码
- 在
config.json.tpl
中替换占位符值以生成正确的config.json
为此,请在.gitattributes
declaration中注册 content filter driver 。
(来自“ Customizing Git - Git Attributes”的图像,来自“ Pro Git book”的图像)
smudge
脚本将(自动在git checkout
或git switch
上生成如上所述的实际config.json
文件。
同样,生成的实际config.json
文件仍然被.gitignore
忽略。
在“ git smudge/clean filter between branches”中查看完整的示例。