简体   繁体   English

Git从远程删除文件

[英]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. 但是,我本地的git clone仅具有该图像文件夹,内部没有图像。

When I use "git push" command, it's working great but deleting all images added by users.. How can I solve this problem? 当我使用“ git push”命令时,它工作得很好,但是删除了用户添加的所有图像。如何解决此问题? [Or, how can I add images (added by users) to git tracking?] [或者,如何将图像(由用户添加)添加到git跟踪中?]

(I'm using openShift) (我正在使用openShift)

You need to use the OPENSHIFT_DATA_DIR to save persistent files. 您需要使用OPENSHIFT_DATA_DIR保存持久文件。 Use a symlink in link it to one of your folders in the repo. 使用符号链接将其链接到存储库中的一个文件夹。

Edit 编辑

post_deploy example post_deploy示例

#!/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. Git适用于文件,而不适用于文件夹。 And if a folder does not contain any files, git assumes the folder itself should not be present either. 并且,如果文件夹不包含任何文件,则git假定该文件夹本身也不应存在。

The most commonly used solution is an empty file .gitkeep in the folder that needs to remain. 最常用的解决方案是在文件夹中保留一个空文件.gitkeep Then, in .gitignore , you add the following: 然后,在.gitignore ,添加以下内容:

images_folder/*
!images_folder/.gitkeep

This tells git to ignore all files in the images folder, except for the one file named .gitkeep . 这告诉git忽略images文件夹中的所有文件,除了一个名为.gitkeep文件。 (So that file must be committed too.) Then there's no reason for git to remove the folder, so your images will remain. (因此也必须提交该文件。)那么git没有理由删除该文件夹,因此您的图像将保留下来。

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

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