简体   繁体   中英

Git deleting files from remote

I have a website. Users can add a picture their profile. So, my website keeping these files in a folder. But, my local git clone only has this image folder without images inside.

When I use "git push" command, it's working great but deleting all images added by users.. How can I solve this problem? [Or, how can I add images (added by users) to git tracking?]

(I'm using openShift)

You need to use the OPENSHIFT_DATA_DIR to save persistent files. Use a symlink in link it to one of your folders in the repo.

Edit

post_deploy example

#!/bin/bash
echo ".................Starting 'post_deploy' Action Hook..................................."
echo ".................attempting 'uploads' setting up symlink........................"
echo "................................................................................"
cd $OPENSHIFT_REPO_DIR/<path to static folder>
ln -s $OPENSHIFT_DATA_DIR/uploads uploads
echo ".................creating 'uploads' completed........................"
echo "................................................................................"

您可以在运行git add命令时跳过该文件夹,也可以git add其更好地添加到.gitignore文件中,如下所示:

your_folder/*

Git works on files, not on folders. And if a folder does not contain any files, git assumes the folder itself should not be present either.

The most commonly used solution is an empty file .gitkeep in the folder that needs to remain. Then, in .gitignore , you add the following:

images_folder/*
!images_folder/.gitkeep

This tells git to ignore all files in the images folder, except for the one file named .gitkeep . (So that file must be committed too.) Then there's no reason for git to remove the folder, so your images will remain.

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