简体   繁体   中英

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;

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

Didn't fix it. Also tried adding to .gitignore */uploads/* , **/uploads/* and /uploads/* .

How do I keep my commits from wiping user uploads when I deploy to Heroku?

The issue isn't with Git¹, but rather with 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. 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. 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.


¹Though it's probably worth verifying that your .gitignore is configured properly, as that can also be an issue. Try running 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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