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

问题描述

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



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

  / var / www / images / *。png 

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



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

解决方案

如果取决于部署如何完成()。

,这是一个

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

问题是与:

一个解决方案是:




  • 确保在 / 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 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:

    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推送和部署后,自动生成的文件将被删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:13