I have a php webapp which has to generate some pdf files in a specified folder. On the production 开发者_StackOverflow中文版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.
First of all I don't understand why the PDF documents are placed inside the source tree. If I where you I always would store uploaded materials in a different folder then the source code of your application.
Secondly, I don't think Git is hiding your PDF's for you. Certainly not if your .gitignore is setup like you say it is. I'm afraid some other process is interfering with your PDF's.
Apart from Git probably not causing this I recommend the following.
- have your application store uploaded materials outside the source code folders of the application itself.
- Don't commit on the server (I don't know if you're doing this, but if it is common practice to fix things on the live environment I can imagine stuff going wrong). On a live server you should only pull code and do absolutely nothing else.
精彩评论