在生产服务器中使用git [英] using git in a production server

查看:154
本文介绍了在生产服务器中使用git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php webapp,它必须在指定的文件夹中生成一些pdf文件。在生产服务器上,我也在使用git,问题是一些pdf文件不时消失。 .gitignore我已经添加了我的pdf文件夹和* .pdf



git是否有可能删除我的* .pdf文件?

$ b $这是一种猜测,因为我们确实需要确切地知道哪些序列的git操作导致文件被删除,以确保。然而,理解(以及被广泛误解)的一个关键点是git的忽略机制是为一次性的文件而设计的,比如构建产品。它不是为珍贵的文件而设计的,但您不想保存在存储库中。 (作为这些陈述的参考,这在这些电子邮件在git邮件列表上。)



为了给你描述的情况提供一个示例场景,假设在版本 a1b2c3 您在存储库中提交了以下文件:

  pdfs / 0001.pdf 
pdfs / 0002.pdf

在历史的某个后期阶段(比如在你目前的 master ),您已经使用 git rm -rf 删除了所有跟踪的PDF,并添加了 pdfs 目录转换为 .gitignore 。但是,您的Web应用程序仍在生成PDF并将它们放入 pdfs 子目录中,现在您有以下被忽略的文件:

  pdfs / 0001.pdf 
pdfs / 0002.pdf
pdfs / 0003.pdf
pdfs / 0004.pdf

现在可能会发生的情况是,如果您决定检查旧版本的代码,请使用:

  git checkout a1b2c3 

... ... git会看到它要更新 pdfs / 0001.pdf pdfs / 0002.pdf 从该版本,并且由于这些路径目前被忽略,因此它决定可以默默覆盖它们。 (毕竟,这就是你想要使用构建产品时所要做的)。

然后,当你返回到 master
$ b $ pre $ g $ c $ g $ c $ g $
$ / code $

... git(非常合理)认为可以删除所有这两个PDF,因为它们已经从 a1b2c3 。所以,你只剩下了:

  pdfs / 0003.pdf 
pdfs / 0004.pdf

...原始被忽略 pdfs / 0001.pdf pdfs / 0002.pdf 您的应用程序创建的消失了。



这可能不是完全发生的情况,但它是一个显而易见的合理行为的例子,可能会导致您的生产服务器丢失一些PDF。



我建议的实际解决方案是创建一个新的目录中 永远不在存储库中的PDF。然后检出不同版本的代码不应该触及那个目录。


I have a php webapp which has to generate some pdf files in a specified folder. On the production server, I'm also using git and the problem is that some pdf files are dissapearing from time to time. On .gitignore I've added my pdf folder and *.pdf

Is there are any chances that git removes my *.pdf files?

解决方案

This is something of a guess, since we'd really need to know exactly which sequence of git operations caused the files to be removed in order to be sure. However, a key point to understand (and which is widely misunderstood) is that git's ignore mechanism is designed for files that are "disposable", such as build products. It's not designed for files that are precious, but which you don't want to keep in the repository. (As a reference for those statements, this is discussed in these emails on the git mailing list.)

To give an example scenario for the situation you describe, suppose that at version a1b2c3 you had the following files committed in the repository:

pdfs/0001.pdf
pdfs/0002.pdf

By some later stage in the history (say at your current master), you have removed all the tracked PDFs with git rm -rf and added the pdfs directory to .gitignore. However, your web application is still generating PDFs and putting them into the pdfs subdirectory, and now you have the following ignored files:

pdfs/0001.pdf
pdfs/0002.pdf
pdfs/0003.pdf
pdfs/0004.pdf

What can now happen is that if you decide to check out the old version of the code, with:

git checkout a1b2c3

... git will see that it wants to update pdfs/0001.pdf and pdfs/0002.pdf from that version, and since those paths are currently ignored, it decides that they can be silently overwritten. (This is what you'd want to happen with build products, after all.)

Then, when you return to master, with:

git checkout master

... git (quite reasonably) thinks it's fine to remove all those two PDFs, since they've been removed from the repository with respect to a1b2c3. So, you're left with just:

pdfs/0003.pdf
pdfs/0004.pdf

... and the original ignored pdfs/0001.pdf and pdfs/0002.pdf that your application created are gone.

This may not be exactly what happened, but it's an example of one apparently reasonable set of actions that could result in losing some PDFs from your production server.

The practical solution that I would suggest is to create a new directory for the PDFs that has never been in the repository. Then checking-out different versions of your code should never touch that directory.

这篇关于在生产服务器中使用git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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