简体   繁体   English

提交时忽略公共上传

[英]Ignore public uploads on commit

I am having an issue where all my user uploaded images are wiped every time I commit any change to the code. 我遇到的问题是,每次对代码进行任何更改时,都会删除所有用户上传的图像。 I figured this is because it is matching the public uploads on the server to what I have locally. 我认为这是因为它使服务器上的公共上载与我本地上的内容相匹配。

So I added /public/uploads/* to .gitignore Then; 所以我在/public/uploads/* .gitignore添加了/public/uploads/*

git rm -r --cached.
git add .
git commit
git push

Didn't fix it. 没有解决。 Also tried adding to .gitignore */uploads/* , **/uploads/* and /uploads/* . 还尝试添加到.gitignore */uploads/***/uploads/*/uploads/*

How do I keep my commits from wiping user uploads when I deploy to Heroku? 部署到Heroku时如何防止提交抹掉用户上传的内容?

The issue isn't with Git¹, but rather with Heroku. 问题不在于Git¹,而在于Heroku。 Its filesystem is ephemeral : any changes made to the filesystem are lost whenever your dyno is restarted: 它的文件系统是短暂的 :只要重新启动测功机,对文件系统所做的任何更改都会丢失:

Each dyno gets its own ephemeral filesystem, with a fresh copy of the most recently deployed code. 每个dyno都有自己的临时文件系统,其中包含最新部署的代码的新副本。 During the dyno's lifetime its running processes can use the filesystem as a temporary scratchpad, but no files that are written are visible to processes in any other dyno and any files written will be discarded the moment the dyno is stopped or restarted. 在dyno的生命周期中,其正在运行的进程可以将文件系统用作临时暂存器,但是任何其他dyno中的进程都看不到已写入的文件,并且在dyno停止或重新启动时,所有写入的文件都将被丢弃。 For example, this occurs any time a dyno is replaced due to application deployment and approximately once a day as part of normal dyno management. 例如,在由于应用程序部署而更换测功机的任何时候都会发生这种情况,并且在正常测功机管理的一部分中大约每天一次。

This happens when you deploy a new version and also in other situations , at least once per day. 在部署新版本时以及在其他情况下 (每天至少一次),会发生这种情况。

The official recommendation from Heroku is to store uploaded files on a third-party service like Amazon S3. Heroku官方建议是将上传的文件存储在第三方服务(如Amazon S3)上。


¹Though it's probably worth verifying that your .gitignore is configured properly, as that can also be an issue. ¹尽管可能值得验证.gitignore的配置正确,因为这也可能是一个问题。 Try running git check-ignore -v public/uploads/some-file-that-exists . 尝试运行git check-ignore -v public/uploads/some-file-that-exists You should see a response referencing the ignore rule that causes that file to be ignored. 您应该看到引用忽略规则的响应,导致该文件被忽略。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM