“git push”删除未跟踪的远程文件 [英] "git push" deletes untracked remote files

查看:150
本文介绍了“git push”删除未跟踪的远程文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个Web服务器,允许用户将图像上传到服务器。但是,我使用 git 来管理我的源代码,并且 git push 操作会删除服务器上与我的本地结帐不匹配的任何内容 - 所以我每次运行 git push



都会丢失图像。起初我以为我可能会以保护上传文件夹,所以我尝试了其他帖子中提到的所有这些内容:


  • 添加了目录到.gitignore,
  • git rm --cached -r uploads

  • git update-index --assume-unchanged uploads



这些都不能解决问题 - 当我做 git push 时,远程目录总是消失。

接下来,我决定把上传的文件放到外面git的工作区域,这样 git push 不会删除它。然后,我创建了一个从公共目录到私人目录的符号链接,以便我可以公开地查看这些文件。到目前为止这么好...但是,每当我运行 git push 它都会删除符号链接!



最后,我认为也许我可以在每次推送时使用 post-receive git钩子来创建符号链接,但是我的web服务器(openshift)已经在使用该钩子进行其他操作,并且不会允许我来编辑它。



确实有这样做的简单方法?!请帮助!

解决方案

您应该使用deploy动作挂钩在OPENSHIFT_DATA_DIR中创建符号链接,您可以查看如何执行的示例在WordPress快速入门这里: https://github.com /openshift/wordpress-example/blob/master/.openshift/action_hooks/deploy



OPENSHIFT_DATA_DIR在部署之间保持不变,但不会在缩放应用程序。


I am running a web server that allows users to upload images to the server. However, I am using git to manage my source code, and the git push operation deletes anything on the server which doesn't match my local checkout - so I lose the images every time I run git push!

At first I thought that I might be able to protect the uploads folder, so I tried all of these things as suggested in other posts:

  • adding the directory to .gitignore,
  • git rm --cached -r uploads
  • git update-index --assume-unchanged uploads

None of these solve the issue - the remote directory always disappears when I do git push.

Next, I decided to put the uploaded files outside of git's working area, so that git push does not delete it. Then I created a symbolic link from the public directory to the private directory so I can see the files publicly. So far so good... However, whenever I run git push it deletes the symbolic link!

Finally, I thought that perhaps I could use a post-receive git hook to create the symbolic link every time I push, but my web server (openshift) is already using that hook for something else and won't allow me to edit it.

There is surely a simple way of doing this?! Please help!

解决方案

You should create symlinks into the OPENSHIFT_DATA_DIR using the deploy action hook, you can view a sample of how to do that in the WordPress quickstart here: https://github.com/openshift/wordpress-example/blob/master/.openshift/action_hooks/deploy

The OPENSHIFT_DATA_DIR persists between deploys, but is NOT shared between gears in a scaled application.

这篇关于“git push”删除未跟踪的远程文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆