Git推送和部署后,自动生成的文件将被删除 [英] After Git push and deployment an auto-generated file gets deleted

查看:196
本文介绍了Git推送和部署后,自动生成的文件将被删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

/ var / www / 位置,我们有一个带有WordPress项目的PHP服务器。整个 / www / root在Git的源代码控制下。所以当我推出新的代码时,它将立即部署并获得新的新代码。



在某些时候,我们使用服务器上的图像构建工具,它可以从我们提供的一些数据生成图像在某些包中,如。

  / var / www / images / *。png 

所以我成功地在该位置生成图像; 但是当我添加新的更改并重新部署时,git将从 中删除所有这些 png 文件。



我累了把这个添加到 git ignore ,但这并没有帮助解决问题。

解决方案


如果我在该位置生成图像,我得到的图像,但是当我添加新的更改,并再次部署git删除所有png文件从包中。


如果取决于部署如何完成( Git 2.3+有推动部署,例如)。

通常,这是一个 post-receive hook ,这是一个

  git --work- tree = / path / to / deploy checkout -f  - 。 

问题是与 -f / - 强制选项从git结帐


切换分支时,即使索引或工作树与 HEAD 不同,也继续进行。


一个解决方案是:




  • 确保在 / path / to / deploy
  • git checkout -f



  • 这意味着后接收钩将如下所示:

      git  - work-tree = / path / to / deploy checkout -f  - 。 
    ln -s / path / to / pngs / path / to / deploy / png


    We have a PHP server with WordPress project on /var/www/ location. Entire /www/ root is under source control in Git. So when I push new code it deploys immediately and we get new fresh code.

    At some point we have use image building tool on server which generates images from some data we put that in some package like.

    /var/www/images/*.png
    

    So I successfully generate image on that location; but when I add new changes and deploy again git removes all these png files from package.

    I tired to add this to git ignore but that didn't help solve the problem.

    解决方案

    if I generate image on that location I get the image but when I add new changes and deploy again git remove this all png files from package.

    If depends on how the deployment is done (Git 2.3+ has a push to deploy, for instance).
    Usually, this is a post-receive hook, which does a

    git --work-tree=/path/to/deploy checkout -f -- .
    

    The issue is with the -f/--force option from git checkout:

    When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes.

    One solution is to:

    • make sure to generate the png in a folder outside /path/to/deploy
    • restore a symlink to that outside folder after the git checkout -f

    That means the post-receive hook would look like:

    git --work-tree=/path/to/deploy checkout -f -- .
    ln -s /path/to/pngs /path/to/deploy/png 
    

    这篇关于Git推送和部署后,自动生成的文件将被删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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